System.InvalidOperationException: LINQ 表达式 'GroupByShaperExpression:
System.InvalidOperationException: The LINQ expression 'GroupByShaperExpression:
我尝试获取特定位置项目的摘要。我尝试对它们进行分组,因为一个项目可以在特定位置多次出现,并获取该项目的摘要 item.It 可以很好地与 ITEMID 和 REMAIN 一起使用,但是当我尝试访问 Description 时它失败了
我的命令看起来像这样
var items1 = await _context.Set<Comitemtran>()
.Include(c => c.Bzitem)?
.Include(c => c.Bzchopp)?
.Include(c => c.Bzitemlot)?
.Include(c => c.Bzstoreplace)?
.Where(c => c.Bzstoreplaceid == placecode).GroupBy(c => c.Bzitemid).Select(group => new ItemTransView
{
BZITEMID = group.Key,
BZDESC = group.Where(c => c.Bzitemid == group.Key).FirstOrDefault().Bzitem.Bzdesc,
BZREMAIN = group.Sum(s => s.Bzquantity)
}).ToListAsync();
当我执行它时,我收到邮递员的回复:
System.InvalidOperationException: The LINQ expression
'GroupByShaperExpression: KeySelector: c.BZITEMID,
ElementSelector:EntityShaperExpression:
EntityType: Comitemtran
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False .Select(s => s.Bzitem.Bzdesc) .First()' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or
'ToListAsync'.
将 Description
添加到分组键。在这种情况下,查询将被翻译成 SQL
var items1 = await _context.Set<Comitemtran>()
.Where(c => c.Bzstoreplaceid == placecode)
.GroupBy(c => new { c.Bzitemid, c.Bzitem.Bzdesc })
.Select(group => new ItemTransView
{
BZITEMID = group.Key.Bzitemid,
BZDESC = group.Key.Bzdesc,
BZREMAIN = group.Sum(s => s.Bzquantity)
})
.ToListAsync();
请注意,Include
后跟 Select
时会被忽略。
我尝试获取特定位置项目的摘要。我尝试对它们进行分组,因为一个项目可以在特定位置多次出现,并获取该项目的摘要 item.It 可以很好地与 ITEMID 和 REMAIN 一起使用,但是当我尝试访问 Description 时它失败了 我的命令看起来像这样
var items1 = await _context.Set<Comitemtran>()
.Include(c => c.Bzitem)?
.Include(c => c.Bzchopp)?
.Include(c => c.Bzitemlot)?
.Include(c => c.Bzstoreplace)?
.Where(c => c.Bzstoreplaceid == placecode).GroupBy(c => c.Bzitemid).Select(group => new ItemTransView
{
BZITEMID = group.Key,
BZDESC = group.Where(c => c.Bzitemid == group.Key).FirstOrDefault().Bzitem.Bzdesc,
BZREMAIN = group.Sum(s => s.Bzquantity)
}).ToListAsync();
当我执行它时,我收到邮递员的回复:
System.InvalidOperationException: The LINQ expression 'GroupByShaperExpression: KeySelector: c.BZITEMID, ElementSelector:EntityShaperExpression: EntityType: Comitemtran ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False .Select(s => s.Bzitem.Bzdesc) .First()' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.
将 Description
添加到分组键。在这种情况下,查询将被翻译成 SQL
var items1 = await _context.Set<Comitemtran>()
.Where(c => c.Bzstoreplaceid == placecode)
.GroupBy(c => new { c.Bzitemid, c.Bzitem.Bzdesc })
.Select(group => new ItemTransView
{
BZITEMID = group.Key.Bzitemid,
BZDESC = group.Key.Bzdesc,
BZREMAIN = group.Sum(s => s.Bzquantity)
})
.ToListAsync();
请注意,Include
后跟 Select
时会被忽略。