EF4.1: Possible to have zero-or-one to zero-or-one (0..1 to 0..1) relationship?

前端 未结 3 691
轮回少年
轮回少年 2021-01-14 10:41

.NET 4.0 with SQL Server 2008 R2. I am trying to represent a 0..1 to 0..1 relationship and I keep getting the following error:

Error 113: Multiplicit

3条回答
  •  日久生厌
    2021-01-14 11:19

    This was possible in a number of ways with SQL 2008 (e.g. filtered index, constraint on computed column) and is default functionality on unique index in SQL 2012.

    According to the ANSI standards SQL:92, SQL:1999, and SQL:2003, a UNIQUE constraint should disallow duplicate non-NULL values, but allow multiple NULL values. SQL's support for this is somewhat recent, but not non-standard.

    Note that just as a 0..1 to many relation can have zero of either and still be perceived as having a dependent column, so can a 0..1 to 0..1 relation.

    Note that EF5 (newer than this this Ladislav's answer) also supports this, but the direction of the dependency is determined by the order in which the 0..1 is set in the design if you are using Model-First. However, it does still seem to be deterministic.

提交回复
热议问题