c# - Am I building the wrong entities in MVC? -


goal. have "gift" entity describes has offer (babysitting, dog walking, etc) rating. , want "giftcategory" entity gives general category descriptive information (pets, sports, automotive, etc) search apon , gift have categories. "gift" entity can have multiple "giftcategory" entities associated it. want ability search category , pull out "gift" entities have been created categories associated them. here have far doesn't seem work entity first approach. maybe need table connects 2 entities because way 2 tables connected doesn't seem correct?

gift entity:

public class gift {     public int id { get; set; }     public string name { get; set; }     public icollection<giftcategory> categories { get; set; } // incorrect???     public int rating { get; set; } } 

category entity:

public class giftcategory {     public int id { get; set; }     public string name { get; set; }     public string description { get; set; } } 

the "giftcategory" table gets created creates gift_id column links "giftcategory" gift (not want)!!!!

it seems need create entity connects 2 entities? like:

public class connectgifts {     public int id { get; set; }     public string giftid{ get; set; }     public string giftcategoryid{ get; set; } } 

this way can have multiple categories gift, thing don't understand entity first don't need entity need table get/query "giftcategory" entities ids gift ids gifts. seems creating entity overkill? there way without creating third table/entity ("connectgifts") code first? or not understanding entities tables , tables entities? i'm using linq-to-sql querying.

you're looking many-to-many relationship , can defined as:

public class gift   {     public int id { get; set; }     public string name { get; set; }     public icollection<giftcategory> categories { get; set; } // incorrect???     public int rating { get; set; } }  public class giftcategory {     public int id { get; set; }     public string name { get; set; }     public icollection<gift> gifts { get; set; } } 

so each has collection of other. gift has many categories , category had many gifts. use bridge table you've done connectgifts it's not necessary ef. using gift , giftcategory, ef create bridge table you.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -