实体框架核心多个索引过滤器不起作用

时间:2019-06-27 16:55:03

标签: c# entity-framework-core

这是我的模特

public class Record
{
    public int Id { get; set; }
    public int Operator { get; set; }
    public bool IsActive { get; set; }
    public bool IsSessionActive { get; set; }
}

基本上我创建了该索引

      modelBuilder.Entity<Record>().HasIndex(r => r.Operator )
            .HasName("Record_Filtered_Index")
            .HasFilter("([IsActive]=(1)) OR ([IsSessionActive]=(1))")
            .IsUnique();

这应该限制我在两个布尔值都为true时为同一运算符插入记录。

我尝试单独创建

modelBuilder.Entity<Record>().HasIndex(r => r.Operator )
            .HasName("Record_Filtered_Index")
            .HasFilter("([IsActive]=(1)")
            .IsUnique();

modelBuilder.Entity<Record>().HasIndex(r => r.Operator )
            .HasName("SessionActive_Filtered_Index")
            .HasFilter("([IsSessionActive]=(1)")
            .IsUnique();

但是最终结果是第一个过滤器基本上什么也不做,第二个过滤器按预期工作,因此基本上覆盖了它。

所以我的问题是...如何确保每个操作员的布尔值均处于活动状态,所以只有一条记录?

0 个答案:

没有答案
相关问题