ef code first - Several identical many-to-many relationships with attributes with one entity class for each of the linking tables -
i have email
entity has to
, cc
, , bcc
collections of contact
entities. relationships many-to-many , need ordering emails in to
, cc
, bcc
. have introduce 3rd entity inbetween - emailcontactassignment
additional sortorder
property.
now because have 3 distinct many-to-many relationships here need 3 of these relationship tables.
the solution see @ moment have 3 relationship entity classes: emailtocontactassignment
, emailcccontactassignment1
, emailbcccontactassignmnet
. appears cannot have base of operations class navigation properties , empty sub-classes each of 3. i'll need have same navigation properties duplicated in each of sub-classes.
is possible still utilize 1 entity have 3 separate many-to-many relationships entity to
, cc
, bcc
relationships?
is possible still utilize 1 entity have 3 separate many-to-many relationships entity to, cc , bcc relationships?
if map separate tables no not possible.
it appears cannot have base of operations class navigation properties , empty sub-classes each of 3. i'll need have same navigation properties duplicated in each of sub-classes.
you define interface mutual properties @ to the lowest degree have consistent contract work with.
public interface icontactassignment { int sortorder { get; set; } icollection<contact> contacts { get; set; } } public class emailtocontactassignment : icontactassignment { // ... } public class emailcccontactassignment : icontactassignment { // ... } public class emailbcccontactassignment : icontactassignment { // ... }
and in dbcontext:
protected override onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<emailtocontactassignment>() .totable("emailtocontactassignmentxref"); modelbuilder.entity<emailcccontactassignment>() .totable("emailcccontactassignmentxref"); modelbuilder.entity<emailbcccontactassignment>() .totable("emailbcccontactassignmentxref"); }
entity-framework ef-code-first entity-framework-6
No comments:
Post a Comment