entity framework - EF 0..1 to 0..1 relationship without shared primary key -
i have 2 entities configure optional 1-1 relationship (i.e. 0..1 0..1). using key on 1 entity, while having navigation properties in both directions.
consider following simplified example illustrate:
public class person { public int personid { get; set; } public int? ticketid { get; set; } public virtual ticket ticket { get; set; } } public class ticket { public int ticketid { get; set; } public virtual person person { get; set; } }
there number of people, , number of tickets. person can possess @ 1 ticket. there people no ticket, , unclaimed tickets.
i thought following might work:
modelbuilder.entity<person>() .hasoptional(p => p.ticket) .withoptionalprincipal(t => t.person);
but creates additional id on ticket table.
i know possible using 2 optional relationships, not ideal solution requires 2 calls savechanges, , not guarantee referential integrity (e.g. person1 own ticket1, ticket1 point person2).
similar questions have focussed on 1-0..1 relationship principal entity's primary key can used on dependent - not suitable either.
i using ef6 code-first.
Comments
Post a Comment