Я сталкиваюсь с следующей ошибкой, пытаясь выполнить запрос LINQ. Мне нужно извлечь все чаты для текущего пользователя, а также последнее сообщение (заказано By Clease) в каждом чате в одном запросе. < /P>
public async Task GetChats()
{
return await (
from uc in context.UserChats
where uc.UserId == httpContextProvider.CurrentUserId
join x in context.Chats on uc.ChatId equals x.Id
from lastMessage in x.Messages
.OrderByDescending(m => m.CreatedAt)
.Take(1)
.DefaultIfEmpty()
select new ChatResponse(
x.Id,
x.Name,
x.Description,
x.ChatType,
x.UserChats.Count(),
true,
lastMessage.Content,
lastMessage.CreatedAt,
lastMessage.User.UserName
)).ToListAsync();
}
< /code>
ошибка: < /p>
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: The LINQ expression 'DbSet()
.Where(m => EF.Property(StructuralTypeShaperExpression:
SnapTalk.Domain.Entities.ChatEntity
ValueBufferExpression:
ProjectionBindingExpression: Inner
IsNullable: False
, "Id") != null && object.Equals(
objA: (object)EF.Property(StructuralTypeShaperExpression:
SnapTalk.Domain.Entities.ChatEntity
ValueBufferExpression:
ProjectionBindingExpression: Inner
IsNullable: False
, "Id"),
objB: (object)EF.Property(m, "ChatId")))
.OrderByDescending(m => m.CreatedAt)' could not be translated. Additional information: Translation of member 'CreatedAt' on entity type 'MessageEntity' failed. This commonly occurs when the specified member is unmapped. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Подробнее здесь: https://stackoverflow.com/questions/793 ... n-properti
Основное ядро Ontity Framework: запрос LINQ с OrderBydescending и навигационными свойствами не переводится в SQL ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как генерировать левое соединение в условиях, используя ядро Ontity Framework
Anonymous » » в форуме C# - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ef core .net 8 - include () и theninclude () с нулевыми навигационными свойствами
Anonymous » » в форуме C# - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-