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.

  1. i found if entity class has collection, collection instantiated in default constructor. why need that?

  2. the icollection<t> instantiated hashset<t> in default constructor. why hashset<t> used? can use list<t> or else?

  3. 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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -