1

I'm trying to achieve the below:

modelBuilder.Entity<CompanyBranches>().HasQueryFilter(m => !m.IsDeleted);
        modelBuilder.Entity<CompanyManagerDetails>().HasQueryFilter(m => !m.IsDeleted);
        modelBuilder.Entity<CompanyOwnerDetails>().HasQueryFilter(m => !m.IsDeleted);
        modelBuilder.Entity<CompanyPartnerDetails>().HasQueryFilter(m => !m.IsDeleted);
        modelBuilder.Entity<TradeLicenseAttachments>().HasQueryFilter(m => !m.IsDeleted);

By using the below so as to stop repetition:

    foreach (var pb in modelBuilder.Model
        .GetEntityTypes()
        .SelectMany(t => t.GetProperties())
        .Where(p => p.Name == "IsDeleted")
        .Select(p => modelBuilder.Entity(p.DeclaringEntityType.ClrType)))
    {

        pb.HasQueryFilter(m => !m.IsDeleted); //Bug here due to Type or Delegate issue
    }

Basically, I'm trying to avoid entering the queryfilter individually. I want to target all models property (IsDeleted) in order to achieve soft delete

Ifeanyi Chukwu
  • 3,187
  • 3
  • 28
  • 32
  • Duplicate. Check https://stackoverflow.com/questions/45812459/ef-core-2-apply-hasqueryfilter-for-all-entity https://stackoverflow.com/questions/45096799/filter-all-queries-trying-to-achieve-soft-delete/45097532 – Vitaliy Smolyakov Jun 25 '21 at 18:48

0 Answers0