.NET CORE 2 EF Include

前端 未结 2 647
北恋
北恋 2021-01-18 10:02

I am using new .net core and EF.

I need help with include linq command. I have some 1:N models and if the collection contais some data marked like deleted I do not w

相关标签:
2条回答
  • 2021-01-18 10:22

    You can configure a Query Filter in your DbContext.

    modelBuilder.Entity<Administrator>()
                .HasQueryFilter(admin => !EF.Property<boolean>(admin, "IsDeleted"));
    

    should do the trick

    Reference link: https://docs.microsoft.com/en-us/ef/core/querying/filters

    0 讨论(0)
  • 2021-01-18 10:25

    You should change the inner condition using Any instead of Where, as:

    .Include(z => z.WorkPlaces)
    .Where(x => x.WorkPlaces.Any(y => !y.IsDeleted))
    
    0 讨论(0)
提交回复
热议问题