c# - Entity Framework:Why the collection type of entity class need to be instanced in the default constructor? -
i using visual studio build code first model of northwind database automatically. have questions.
i found if entity class has collection, collection instantiated in default constructor. why need that?
the
icollection<t>
instantiatedhashset<t>
in default constructor. whyhashset<t>
used? can uselist<t>
or else?why navigation property @ one side (one many relation)
icollection<t>
,virtual
?
to implement entity class in way mention above, think there must benefits can brought. can tell me why?
public partial class orders { public orders() { order_details = new hashset<order_details>(); } public virtual icollection<order_details> order_details { get; set; } }
i found if entity class has collection, collection instantiated in default constructor. why need that?
you don't. needs instantiated before start adding stuff it.
the icollection instantiated hashset in default constructor. why hashset used? can use list or else?
you can use implements icollection<t>
concrete implementation.
why navigation property @ "one" side (one many relation) icollection , virtual?
icollection<t>
interface ef expects navigation properties. provides minimal interface necessary represent type of relationship. virtual ef can insert proxy @ runtime detect changes property. if decide not make virtual, need manually inform ef changes property.
Comments
Post a Comment