Skip to content

Does not help with implementing basic OOP #2820

Closed
@DimitryNechaev

Description

@DimitryNechaev

This article implies that if I have 10 entities which have the same field "IsDeleted" I need to copy-paste the filter 10 times.
Basic OOP expects to have a single base entity with the field and the rule applied on the base level.

At the moment I greatly struggle with EF Core trying to do exactly this and nowhere can find applicable article.
In my case a large number of 3rd pty tables having StatusId field, which I mage though basic abstract class HasStatus.

The best so far is that I manage to enumarate though all entities but can't apply a filter, as there is no generic to accept the base type. HasQueryFilter accepts LambdaExpression, which is a bummer.

        foreach (var entity in modelBuilder.Model.FindLeastDerivedEntityTypes(typeof(HasStatus)))
        {
            modelBuilder.Entity(entity.ClrType)
                .HasQueryFilter(t => t.StatusID == 1);
       }

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

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