Hi Helpies I am new to EF and linq queries
var chatEntryDetails = await
(
from chatEntry in dbChatEntry
where chatEntry.ChatId == chat.Id
join groupMembers in dbGroupMember on chatEntry.GroupMemberId equals groupMembers.Id
join user in dbUser on groupMembers.UserId equals user.Id
join countChatEntryUserStatus in dbChatEntryUserStatus.Where(e => e.DateReadByUser != null).Count() on chatEntry.Id equals countChatEntryUserStatus.ChatEntryId
join chatEntryUserStatus in dbChatEntryUserStatus.Where(e => e.GroupMemberId == groupMemberId) on chatEntry.Id equals chatEntryUserStatus.ChatEntryId into ce
from chatEntryUserStatus in ce.DefaultIfEmpty()
orderby chatEntry.CreateDateTime descending
select new ChatEntryDetails
{
UserId = user.Id, GreetingName = user.GreetingName, GroupMemberId = chatEntry.GroupMemberId,
CreateDateTime = chatEntry.CreateDateTime, Details = chatEntry.Details, ChatType = ToApi(chatEntry.ChatType),
DateReadByUser = chatEntryUserStatus.DateReadByUser, ChatEntryId = chatEntry.Id, ReadByCount = countChatEntryUserStatus
}
)
.PerPage(page, perPage)
.ToListAsync();
When Executing this I got the following error
Could not find an implementation of the query pattern for source type 'IQueryable<<anonymous type: <anonymous type: <anonymous type: <anonymous type: ChatEntryDb chatEntry, GroupMemberDb groupMembers> <>h__TransparentIdentifier0, UserDb user> <>h__TransparentIdentifier1, IEnumerable<ChatEntryUserStatusDb> ce> <>h__TransparentIdentifier2, ChatEntryUserStatusDb chatEntryUserStatus>>'. 'Join' not found. [UserServerApiLib]
Everything works fine without this line
join countChatEntryUserStatus in dbChatEntryUserStatus.Where(e => e.DateReadByUser != null).Count() on chatEntry.Id equals countChatEntryUserStatus.ChatEntryId
Here I want the count chatEntryUserStatus where DateReadByUser is not null This line is supposed to get the count from chatEntryUserStatus table with few conditions there is one table chatEntry and they related as chatEntry.id = chatEntryUserStatus.ChatEntryId and for every chatEntry it has multiple records in chatEntryUserStatus so I want that count from chatEntryUserStatus for every chatEntry
If not count then If I can get all the chatEntryUserStatus records for every chatEntry
Thanks in advance
question from:https://stackoverflow.com/questions/66059251/count-in-linq-query-with-multiple-join-ef