I am wondering if it is possible to map a m:n relationship in the database twice in a EF4 Model.
Consider this database model:
http://andarki.dk/stackoverflow/db.png
It is a standard m:n relationship between companies and users.
If the field works_at.is_locked_out is ignored during model generation it generates a nice * to * relationship in EF:
http://andarki.dk/stackoverflow/pretty.png
If i enable works_at.is_locked_out it looks more like the original db schema:
http://andarki.dk/stackoverflow/detailed.png
Is it possible to have both relations at once?
For some queries works_at.is_locked_out isn’t necessary and having the direct link makes it easier to query in those cases.
When i add both relations i get the error
Problem in mapping fragments starting at lines 23, 30:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
TestModel.edml
Is this in any way possible or is it a case of me trying to have my cake and eating it too?
Both at the same time is not possible as you see with the error you are presented. This article by Julie Lerman will explain a lot, if not all. And I think you should go for alternative 2, because as you said it isn’t always necessary, but sometimes (or in the near future) it is. That field isn’t there without any purpose I guess… 😉 Good luck!