in the past I faced an issue with duplicate values in db so I added some composite contraint
Entity Framework Core Prevent Duplicate Values, Add specific constraint
Today I noticed I was able to add a duplicate record in the database. The following constraint does not work as expected, it only works for the activated sales, which is giving me impression that the following configuration using fluentapi is overiding. How to make sure I can apply both so I have only 1 constraint for pending sales AND 1 constraint for activated sales.
//preventing more than 1 pending sale in db for one user THIS ONE IS NOT APPLIED
modelBuilder.Entity<Sale>().HasIndex(e => new { e.SaleStatus, e.UserObjectId }).IsUnique().HasFilter("[SaleStatus] = 0");
//preventing more than 1 activated sale for 1 user in db THIS ONE WORKS AS EXPECTED
modelBuilder.Entity<Sale>().HasIndex(e => new { e.SaleStatus, e.UserObjectId }).IsUnique().HasFilter("[SaleStatus] = 5");
I tried to change the order and also tried to apply them in a separate migrations but it always works only for one of them.