How can I stop EF Core from creating a filtered index on a nullable column

后端 未结 1 1675
我寻月下人不归
我寻月下人不归 2020-12-06 16:55

I have this model:

public class Subject
{
    public int Id { get; set; }

    [Required]
    [StringLength(50)]
    public string Name { get; set; }

    pu         


        
相关标签:
1条回答
  • 2020-12-06 17:44

    Creating filtered index excluding NULL values is the default EF Core behavior for unique indexes containing nullable columns.

    You can use HasFilter fluent API to change the filter condition or turn it off by passing null as sql argument:

    entityBuilder.HasIndex(e => new { e.LevelId, e.Name, e.DeletedAt })
        .IsUnique()
        .HasFilter(null);
    
    0 讨论(0)
提交回复
热议问题