efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Entity Framework Core multiple filters index unique

Open jfcaldeira opened this issue 7 years ago • 1 comments

    modelBuilder.Entity<Registo>().HasIndex(r => r.IsArranqueActivo)
            .HasName("IsArranqueActivo_Filtered_Index")
            .HasFilter("([ValidatedComponentes]=(1)) AND ([ValidatedGeometrias]=(1)) AND ([ValidatedPokayokes]=(1))")
            .IsUnique();

I tried inserting on the column and it still allowed, what am i doing wrong?

I need the IsArranqueActivo to deny inserts if the other 3 columns are false

I might be wrong though on the way i am approaching but i don't know how to make a constraint with EF Core

jfcaldeira avatar Jun 26 '19 08:06 jfcaldeira

What i was looking for is a check constraint which can be done using SQL directly on migrations.

jfcaldeira avatar Jun 26 '19 17:06 jfcaldeira