❔ Why .Where() doesn't work with .Include()?
I need to fetch chats that have current user as a participant, and want to fetch only active users.
I execute the following query:
but participants filtering part doesn't work - all the users are included, while it works as intended with 'select only chats with current user as participant' condition.
https://i.stack.imgur.com/WDA6h.png
I execute the following query:
var query = _db.Chats
.Include(c => c.Participants.Where(cu=>cu.IsActive))
.Include(c=>c.LastMessage)
.ThenInclude(m => m.Sender)
.ThenInclude(cu => cu.User)
.Where(c =>
c.Participants.Any(cu => cu.UserId == _currentUser.MessengerUserId))
.OrderByDescending(c => c.LastMessage != null ? c.LastMessage.Timestamp : c.Created)
.AsNoTracking();but participants filtering part doesn't work - all the users are included, while it works as intended with 'select only chats with current user as participant' condition.
https://i.stack.imgur.com/WDA6h.png
- Code with Resharper Annotations
https://pastebin.com/Bvsxju91- Generated PgSql script

Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Stack Overflow
I need to fetch chats that have current user as a participant, and want to fetch only active users.
I execute the following query:
var query = _db.Chats
.Include(c => c.Participants....
I execute the following query:
var query = _db.Chats
.Include(c => c.Participants....