c# - Entity Framework: How to have 2 properties referring to same other table -




so imagine have simple database system can receive boxes (incoming) , send boxes (outgoing). 1 box has multiple boxcontent, "a" boxcontent can have incoming box (when arrived) outgoing box (when gets sent away).

but when have structure this, entity framework adds "box_id" column database table of boxcontent.

here's entities:

public class boxcontentitem {     public box incomingbox { get; set; }     public box outgoingbox { get; set; } }  public class box {     public ilist<boxcontentitem> boxcontentitems { get; set; } } 

so how make ilist<boxcontent> boxcontent link either box incomingbox or box outgoingbox?

you can use inverseproperty attribute on box entity, need add additional property like:

public class box {     [inverseproperty("incomingbox")]     public ilist<boxcontentitem> incomingboxcontentitems { get; set; }      [inverseproperty("outgoingbox")]     public ilist<boxcontentitem> outgoingboxcontentitems { get; set; } } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -