【发布时间】:2020-03-30 14:42:37
【问题描述】:
我正在使用实体框架,并且我有以下模型类:
public class Test
{
public string Name { get; set; }
public int SiteId { get; set; }
public bool IsPrimary { get; set; }
}
如何根据SiteId 将IsPrimary 列设置为唯一?
例如,我可以将多个记录设置为同一SiteId 的IsPrimary 为假,但只有一个设置为真。
【问题讨论】:
-
您希望在数据库或应用程序中强制执行此操作吗?
-
假设数据库,您可以查看使用检查约束:stackoverflow.com/q/13232777/5803406
标签: asp.net asp.net-mvc entity-framework asp.net-core