I’ve just started a project using LINQ to SQL, and I’ve clashed against the many-to-many
problem. I’ve found a lot of possible solution, and I’ve choose this one.
Anyway, the affected db tables look like this:
Customer (idcustomer,other stuff..)
Customer_Role(idcustomer, idrole, other_attribute_I_want_to_keep )
Role(idrole, other stuff)
Now on, how can I handle the “other_attribute_I_want_to_keep?
It would be great to have it like this:
Customer c.Role.other_attribute_I_want_to_keep, but I cannot spot a possible solution.
Thanks
You can’t use many-to-many for this. Rather you’ll need to make CustomerRole a first class object that
BelongsToboth a Customer and a Role. Customer and Role in turn should be each declare aHasOneattribute for CustomerRole. Then you can do:You can make a shortcut
Roleattribute onCustomerdefined as:but be aware that you may run into trouble using this shortcut when building a complex query.