Skip to content

How to apply unique constraint in case of global query filter #25401

Closed as not planned
@nicolapiccinelli

Description

@nicolapiccinelli

Hello,
I cannot find anyway a solution for the following behaviour (maybe is by design, but I cannot figure out if it is): i've setup a query filter to provide global soft delete to my context, but it seems to be ignored by the unique check. Can anyone give me ad advice if there is a solution to achieve this? Right now I'm getting an exception in case of deleted records.

foreach (var type in modelBuilder.Model.GetEntityTypes())
{
    if (type.ClrType.BaseType == typeof(Models.Entities.EFExtensions.BaseEntity))
    {
        modelBuilder.SetSoftDeleteFilter(type.ClrType);
    }
}

modelBuilder.Entity<MyClass>().HasIndex(p => p.Name).IsUnique();

EF Core version: 5.0.1
Database provider: Microsoft.EntityFrameworkCore.SqLite
Target framework: .NET 5.0
Operating system: Linux/MacOs/Windows
IDE: Visual Studio Code

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions