Implementing one-to-zero-or-one relation in SQL Server

后端 未结 2 1178
攒了一身酷
攒了一身酷 2020-12-01 14:55

I\'m using Entity Framework 4.1 database first approach. I\'ve used legacy database. In my edmx file which created entity classes based on tables in the legacy database, the

2条回答
  •  误落风尘
    2020-12-01 15:15

    If the database tables are already designed with a 1:1 relationship (or a 1:0-1), then EF will work with it just fine, although it will pluralize the child table's name (if you let it pluralize).

    The basic approach is to create a foreign key (as if you were making a 1:many relationship), then put a unique index on the foreign key field. Is that what you are aiming to accomplish?

    This might help, too: Designing 1:1 and 1:m relationships in SQL Server .

    On a side note, 1-1 relationships are often not necessary and/or a symptom of a database design that needs rethinking. However, it sounds like you inherited the design... I know all about that!

提交回复
热议问题