ef code first - Unique index with fluent api -


i got table person, order , personorder.

in table personorder have column personid , orderid. how can create unique index between these columns fluent api?

this try:

modelbuilder.entity<personorder>()             .haskey(l => new { l.personid , l.orderid});   [table("personorder")] public class personorder {     public int personid { get; set; }     public int orderid{ get; set; }      public virtual person person { get; set; }     public virtual order order { get; set; } } 

i had think while probably mean. think mean there non-unique indexes on personorder.personid , personorder.orderid.

but there is unique index on primary key personorder.personid + personorder.orderid. , that's thing should unique. index on individual fields can never unique. mean association in fact not many-to-many, one-to-many.

or you're after: have 1 (person) many (orders) association? (with unique personorder.orderid). in case might model association regular 1 many: person.orders , order.person (singular).


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 -