我有如下多对多的关系:
public class ClassAClassB
{
[Key, Column(Order = 0)]
public int ClassAId { get; set; }
[Key, Column(Order = 1)]
public int ClassBId { get; set; }
public bool IsMain { get; set; }
public virtual ClassA ClassA { get; set; }
public virtual ClassB ClassB { get; set; }
}
可以使用数据注释来创建唯一约束 ClassAId和IsMain == true? ClassAId和IsMain == false因为不是唯一的
在SQL中将是:
CREATE UNIQUE NONCLUSTERED INDEX [IX_ClassAIsMain] ON [dbo].[ClassAClassB]
([ClassAId] ASC)
WHERE ([IsMain]=(1))
ON [PRIMARY]