同一个表中两个外键的唯一值

时间:2016-08-21 17:30:25

标签: sql ef-code-first entity-framework-core

我正在使用Entity Frame Core Code First和我正在研究的ASP MVC项目。

我有一个带有两个引用同一个表的外键的表。我遵循了这个很好的例子:Entity Framework Code First - two Foreign Keys from same table

如何强制执行它以使值组合只能存在一次?

Id   Value1    Value
1    1         2        --This is ok
2    1         3        --This is ok
3    1         2        --This is bad. Duplicate combination
4    3         1        --This is bad. This is just the reverse of Id 2

谢谢。

0 个答案:

没有答案
相关问题