Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

entity framework - How to determine the order of Property Loading in CodeFirst?

I was thinking that is there any way to determine the order of property loading in CodeFirst,for example i have a class like below:

public Class
{
 public string Propert1{get;set;}
 public string Propert2{get;set;}
 public List<string> PropertList{get;set;}
}

And i need to make EF to load ProprtyList before property1!(Because i manipulate ProprtyList Values On Property1_Changed).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A property should be just that: a property. I.e. you get or set it and nothing else, no side effects. I know that even some .Net classes that violate this rule, but still it is a very healthy principle. Another principle is that it should not matter in which order properties of an object are being set. That is because setting any individual property should leave an object in a valid state.

So consider your Class object, the way EF materializes it, to be valid. Then you can start modifying it. If you want to modify an object in a way that multiple properties are changed simultaneously, you should do this by calling a method with a descriptive name, not by setting one property and silently changing others.

If you want a list that presents a different content based on PropertList, make a read-only (unmapped) property or a GetXyz() method in which the changed content is generated (without modifying PropertList!) and returned.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...