How to add an EF6 Association to a Candidate Key / Unique Key which is not the Primary Key?

前端 未结 1 1429
滥情空心
滥情空心 2021-01-11 14:57

Using Schema First, I have a database structure, as so

ExternalDataItems
---
edataitem_id   PK -- surrogate         


        
相关标签:
1条回答
  • 2021-01-11 15:22

    Looks like "missing important feature"

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

    You can remove foreign key in DB scheme and use LINQ to join tables:

    from item in ExternalDataItems
    join map in ExternalMaps on item.datahash = map.ext_datahash
    select new { item.edataitem_id, map.emap_id };
    

    Also you can create the VIEW with these joined tables and use the one.

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