.net - Entity Framework Code First mapping composite key in join table where foreign keys are not exposed in model -
.net - Entity Framework Code First mapping composite key in join table where foreign keys are not exposed in model -
i have bring together table additional field relevant join:
virtualdatastreamid int not null datastreamid int not null formulaelement int not null
all columns primary key.
the poco mapped is:
public class virtualdatastreammap { public virtual datastream datastream { get; set; } public virtual virtualdatastream virtualdatastream { get; set; } public virtual string formulaelement { get; set; } }
i not have foreign key properties in model as, me, concept of foreign key implementation detail , should encapsulated relationships specified class. i'd prefer not add together these if possible.
how map fluent api? hoping below (which unfortunately doesn't work):
modelbuilder.entity<virtualdatastreammap>() .haskey(vdm => new { datastreamid = vdm.datastream.id, virtualdatastreamid = vdm.virtualdatastream.id, formulaelement = vdm.formulaelement });
the field names of anonymous type have named object cannot have 2 fields same name.
i see this question issue raised in reply there doesn't seem further.
if it's not possible, improve option?
add foreign key properties model addid
field database , model thanks
each column of composite primary key has mapped scalar property in entity. ideal solution not work.
in alternative 2 have create unique key , check unique key violations. ef not have built in back upwards unique keys. hence pick alternative 1.
.net entity-framework many-to-many ef-code-first
Comments
Post a Comment