How to get EF6 to honor Unique Constraint (on FK) in Association/Relationship multiplicity?

前端 未结 1 1205
礼貌的吻别
礼貌的吻别 2020-12-16 14:59

2019 Update / TLDR; switch to Entity Framework Core (or whatever else)

While missing some \"Features\", EF Core properly honors Alternate K

相关标签:
1条回答
  • 2020-12-16 15:38

    The problem is that Entity Framework (from EF4 through EF6.1, and who knows how much longer) does not "understand" the notion of Unique Constraints and all that they imply: EF maps Code First, not Relational Algebra *sigh*

    This answer for my related question provides a link to a request to add the missing functionality and sums it up:

    .. The Entity Framework currently only supports basing referential constraints on primary keys and does not have a notion of a unique constraint.

    This can be expanded to pretty much all realms dealing with Unique Constraints and Candidate Keys, including the multiplicity issue brought up in this question.


    I would be happy if this severe limitation of EF was discussed openly and made "well known", especially when EF is touted to support Schema First and/or replace L2S. From my viewpoint, EF is centered around mapping (and supporting) only Code First as a first-class citizen. Maybe in another 4 years ..

    0 讨论(0)
提交回复
热议问题