EF Core Linq to SQLite не удалось перевести, работает на SQL ServerC#

Место общения программистов C#
Ответить
Anonymous
 EF Core Linq to SQLite не удалось перевести, работает на SQL Server

Сообщение Anonymous »

У меня есть выражение linq, которое отлично работает в производственной базе данных, но выдает ошибку в SQLite в базе данных памяти тестового контекста. Ошибка, которую я получил, гласит:

Код: Выделить всё

The LINQ expression (EntityShaperExpression:

EntityType: Item
ValueBufferExpression:
(ProjectionBindingExpression: Inner)
IsNullable: True ).Price * (Nullable)(decimal)(EntityShaperExpression:
EntityType: ISItem
ValueBufferExpression:
(ProjectionBindingExpression: Outer)
IsNullable: False ).Qty' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Выражение linq:

Код: Выделить всё

var locationsQuery = context.DbContext.Locations
.Include(x => x.Check)
.Include(x => x.Scan)
.Include(x => x.EScan)
.ThenInclude(es => es!.Items)
.ThenInclude(isi => isi.Item)
.Where(x => x.ProjectId == query.ProjectId)
.Select(x => x);
Тогда у меня есть прогноз:

Код: Выделить всё

LocationId = entity.Id,
LHA = entity.LHA,
Zone = entity.Zone,
Area = entity.Area,
LocationState = $"DB.{nameof(LocationState)}.{entity.State.ToString()}",
CheckUserId = entity.Check != null ? entity.Check.ScanUserId : (int?)null,
ScanUserId = entity.Scan != null ? entity.Scan.ScanUserId : (int?)null,
CheckUserName = entity.Check != null ? entity.Check.ScanUser.Name : null,
ScanUserName = entity.Scan != null ? entity.Scan.ScanUser.Name : null,
SumPrice = entity.EffectiveScan != null // This cannot be evaluated
? entity.EScan.Items
.Where(x => x.Item != null)
.Sum(x => x.Item!.Price * (decimal)x.Qty)
: null,
SumQty = entity.EScan != null
? entity.EScan.Items
.Sum(x => x.Qty)
: (double?)null
Если я удалю расчет SumPrice, он будет работать так, как ожидалось (как в производственной системе). Что я могу сделать, чтобы этот запрос работал одинаково на SqlServer и SQLite в базе данных памяти?

Подробнее здесь: https://stackoverflow.com/questions/605 ... sql-server
Ответить

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

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

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

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

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