Count records not referenced in other table (one-to-many table issue with EF & LINQ)

This one should work. Note that Include is introduced just for loading related data, not filtering main records.

var numRows = await applicationDbContext.TimeLogs
   .Where(t => t.IsBillable == true && t.IsActive == true 
        && !t.Invoices.Where(i => i.IsActive == true).Any())
   .CountAsync();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top