ef code first - Primary key on subentity -


i want model following ef code first. imagine car race, multiple car classes compete in own races.

a subevent 1 carclass, each subevent unique it's id, eventid , carclassid.

now here comes problem: competitor unique in subevent, primarykey competitor has { competitorid, subeventid, eventid, carclassid } (to unique)

so in onmodelcreating() function of context i'd have go following:

modelbuilder.entity<competitor>().key(c => new { c.id, c.subeventid, c.subevent.eventid, c.subevent.cclassid}); 

is right or overcomplicating things here?


for reference, that's code model far.

class event {     int id;     virtual icollection<subevent> subevents; } class subevent {     int id;     int eventid;     int cclassid;      virtual event event;     virtual cclass cclass;     virtual icollection<competitor> competitors;     virtual icollection<race> races; // not shown shortness reasons. } class competitor {     int id;     int subeventid;      virtual subevent subevent;     // snip } class cclass { int id; } 


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -