c# - EF - How to make (composite) foreign key optional -
i have 3 models: order, organisation , orderorganisation.
orderorganisation's existence not mandatory... don't know how tell ef.
currently, if write queries using inner joins instead of outer joins join orderorganisation.
i part of model (if possible) , not in context (as it's large database , think using context fragments logic).
here models.
public class order { public int id { get; set; } public virtual icollection<orderorganisation> orderorganisations { get; set; } } public class organisation { public int id { get; set; } public virtual icollection<orderorganisation> orderorganisations { get; set; } } public class orderorganisation { [key, column(order = 0)] public int orderid { get; set; } [key, column(order = 1)] public int organisationid { get; set; } [foreignkey("orderid")] public virtual order order { get; set; } [foreignkey("organisationid")] public virtual organisation organisation { get; set; } }
what need include please?
i presume need make nullable, can't work out what.
thanks
you not have create cross table on such case on ef. below code enough think
public class order { public int id { get; set; } public virtual icollection<organisation> orderorganisations { get; set; } } public class organisation { public int id { get; set; } public virtual icollection<order> orderorganisations { get; set; } }
then ef create organisationorders named table.
Comments
Post a Comment