c# - Linking/assigning one EF class to other - virtual ICollection isn't present in migrations file -


i have class called "collection". represents data stored in entity framework database. here part of class:

public class collection {    [...]    [foreignkey("primarycollection")]    public int? primarycollectionid { get; set; }    public virtual collection primarycollection { get; set; }    public virtual icollection<collection> collectionsbasedonthisone { get; set; } } 

what wanted accomplish: collection can have "parents" or "children", in "primarycollection" parent , "collectionsbasedonthisone" children.

i called "add-migration" function, visual studio generated is:

addcolumn("dbo.collections", "primarycollectionid", c => c.int()); createindex("dbo.collections", "primarycollectionid"); addforeignkey("dbo.collections", "primarycollectionid", "dbo.collections", "id"); 

i think something's missing. there nothing "virtual icollection collectionsbasedonthisone" in migration. why that?

ps: remember when create, example, class called "people" stores virtual icollection of "person" , "person" has specified variable stores parent ("people" class), entity framework create table like: "peopleperson". shouldn't create similar table case like, hmmm... "collectioncollection"?

what name kind of linking/assigning/connectiong data each other in databases? should in google learn that?

you need intermediary table many-to-many relationship.

for one-to-many relationship yours, need column specifying id of each child's single parent.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -