相关疑难解决方法(0)

SQL to Entity Framework Count Group-By

我需要将此SQL语句翻译成Linq-Entity查询...

SELECT name, count(name) FROM people
GROUP by name
Run Code Online (Sandbox Code Playgroud)

sql linq-to-entities entity-framework group-by count

76
推荐指数
4
解决办法
10万
查看次数

Ef Core 3 .GroupBy() 按日期选择每组之一

基本上我想做与这里相同的事情: https: //stackoverflow.com/a/16274992/4138686,但是在 EF Core 3.1.3 中使用这个答案给了我

System.InvalidOperationException: LINQ 表达式 '(GroupByShaperExpression: KeySelector: (r.Price), ElementSelector:(EntityShaperExpression: EntityType: RetailerRate ValueBufferExpression: (ProjectionBindingExpression: EmptyProjectionMember) IsNullable: False ) ) .OrderByDescending(r => r.CreatedAt)'无法翻译。以可翻译的形式重写查询,或者通过插入对 AsEnumerable()、AsAsyncEnumerable()、ToList() 或 ToListAsync() 的调用来显式切换到客户端计算。有关详细信息,请参阅https://go.microsoft.com/fwlink/?linkid=2101038 。

这是代码:

await _db.RetailerRates
                .GroupBy(r => r.Price)
                .Select(g => g.OrderByDescending(r => r.CreatedAt).First())
                .ToListAsync();
Run Code Online (Sandbox Code Playgroud)

有没有办法根据 EF Core 3.1 中每个组的日期检索第一个元素?

c# group-by ef-core-3.1

6
推荐指数
0
解决办法
4654
查看次数