Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...