c# - Entity Framework Code First: Many to many self referencing, naming convention -


working example

class product {    public int id { get; set; }    public string name { get; set; } }  class color {    public int id { get; set; }    public string name { get; set; } }  class productcolor {     public int id { get; set; }      [foreignkey("productid")]     public product product { get; set; }     public int productid { get; set; }      [foreignkey("colorid")]     public color color { get; set; }     public int colorid { get; set; } } 

after adding , applying migrations, when add product list of productcolors entity context not changed ( no need add , apply new migration )

class product {     ...     public virtual icollection<productcolor> productcolors { get; set; } } 

this ok.

not working example

but how name list inside product, if need reference products products ? example

class productform {     public int id { get; set; }      [foreignkey("productid")]     public product product { get; set; }     public int productid { get; set; }      [foreignkey("formid")]     public product form { get; set; }     public int formid { get; set; }      public producttype producttype { get; set; } } 

when try add list

class product  {     ...     public virtual icollection<productform> productforms { get;set;} } 

this change entity context. wrong.

thanks.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -