У меня есть метод из моего контекста БД, который выглядит следующим образом:
public override async Task<IEnumerable<FeedMessage>> GetLatestFeeds(
int userId,
int groupId,
int maxResults = 15,
long lastId = 0)
{
if (lastId == 0) lastId = long.MaxValue;
var userSpecific =
FeedMessages.Where(fm =>
fm.UserId.HasValue && fm.UserId.Value == userId && fm.Id < lastId && !fm.IsDeleted);
var groupSpecific =
FeedMessages.Where(fm =>
fm.UserId == null && fm.GroupId.HasValue && fm.GroupId.Value == groupId && fm.Id < lastId && !fm.IsDeleted);
var siteWide =
FeedMessages.Where(fm =>
fm.UserId == null && fm.GroupId == null && fm.Id < lastId && !fm.IsDeleted);
var feeds = await
userSpecific.Union(groupSpecific).Union(siteWide)
.OrderByDescending(x => x.Id)
.Take(maxResults)
.ToListAsync();
return feeds.OrderBy(x => x.Id);
}
Идея в том, что я хочу получить записи, которые относятся к конкретному пользователю, группе или общему назначению, упорядочить их по идентификатору и вернуть лучшие результаты X.
Если я запускаю это, я получаю целый экран ошибок:
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Union({from FeedMessage fm in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[MySolution.Common.Entities.FeedMessage]) where ((((([fm].UserId == null) AndAlso ([fm].GroupId != null)) AndAlso (Convert([fm].GroupId, Int32) == __groupId_2)) AndAlso ([fm].Id < __lastId_3)) AndAlso Not([fm].IsDeleted)) select [fm]})' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Union({from FeedMessage fm in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[MySolution.Common.Entities.FeedMessage]) where (((([fm].UserId == null) AndAlso ([fm].GroupId == null)) AndAlso ([fm].Id < __lastId_4)) AndAlso Not([fm].IsDeleted)) select [fm]})' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Union({from FeedMessage fm in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[MySolution.Common.Entities.FeedMessage]) where ((((([fm].UserId == null) AndAlso ([fm].GroupId != null)) AndAlso (Convert([fm].GroupId, Int32) == __groupId_2)) AndAlso ([fm].Id < __lastId_3)) AndAlso Not([fm].IsDeleted)) select [fm]})' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Union({from FeedMessage fm in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[MySolution.Common.Entities.FeedMessage]) where (((([fm].UserId == null) AndAlso ([fm].GroupId == null)) AndAlso ([fm].Id < __lastId_4)) AndAlso Not([fm].IsDeleted)) select [fm]})' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'orderby [x].Id desc' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Take(__p_5)' could not be translated and will be evaluated locally.
Что здесь происходит? И как мне это исправить? Это будет большая таблица, локальная оценка сокрушит систему.