Я сталкиваюсь с следующей ошибкой, пытаясь выполнить запрос 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#
Место общения программистов C#
1737817267
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.
Подробнее здесь: [url]https://stackoverflow.com/questions/79386955/entity-framework-core-linq-query-with-orderbydescending-and-navigation-properti[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия