Relationship mapping without relationship entity class #2780
-
Considering 3 tables in database, they are referenced in a many to many relationship and the intermediate table (TB_PRODUCT_FIELD) have an extra column. TB_PRODUCT ( ID, Name )
TB_FIELD ( ID, Name )
TB_PRODUCT_FIELD ( --> Intermediate table, many-to-many
ProductID,
FieldID,
Order --> Extra column
) I have 2 classes: class Product {
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual IList<Field> Fields { get; set; }
}
class Field {
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual short Order { get; set; }
} I would like to create this relationship without creating the relationship entity class itself (TB_PRODUCT_FIELD). I got this working before adding this new column named "Order" but now I couldn't get the value from that in Is it possible to do that? If so, how? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
If that is a true many-to-many, then modeling it with theses classes looks like an error: a field could have different orders, one for each product it is bound to. |
Beta Was this translation helpful? Give feedback.
If that is a true many-to-many, then modeling it with theses classes looks like an error: a field could have different orders, one for each product it is bound to.
Otherwise you may use a formula for mapping your Order column, something like
formula="(select top 1 pf.Order from TB_PRODUCT_FIELD pf where pf.FieldID = ID)"
.