Основное ядро ​​Ontity Framework: запрос LINQ с OrderBydescending и навигационными свойствами не переводится в SQLC#

Место общения программистов C#
Ответить
Anonymous
 Основное ядро ​​Ontity Framework: запрос LINQ с OrderBydescending и навигационными свойствами не переводится в SQL

Сообщение Anonymous »

Я сталкиваюсь с следующей ошибкой, пытаясь выполнить запрос 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»