实体框架核心组

时间:2019-01-14 14:25:21

标签: c# entity-framework-core

我有这个查询

items = await context.Bookings
                        .GroupBy(p => p.Start.Day, p => p.BookedById, (key, g) => new KeyValuePair<int, decimal>(key, g.Distinct().Count()))
                        .ToListAsync(cancellationToken);

它给我错误: 警告'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning生成的错误:LINQ表达式'GroupBy([p] .Start.Day,[p] .BookedById)'无法翻译,将在本地进行评估

但是如果我将其更改为double group by

items = await context.Bookings
                    .GroupBy(p => new { p.Start.Day, p.BookedById })
                    .Select(c => new { c.Key.Day, c.Key.BookedById, Count = c.Count() })
                    .GroupBy(z => z.Day)
                    .Select(c => new KeyValuePair<int, decimal>(c.Key, c.Count()))
                    .ToListAsync(cancellationToken);

有效 有什么办法不只使用双组别吗?

换句话说,我想要的是当天预订的唯一用户列表计数

lets have this sample of data: day, user, bookingsCount {(1, ad, 2), (1, ac, 3), (2, be, 1), (2, be 3)} so the result should be dayNumber, usersCount: (1,2) , (2, 1)

,并且Bookings类至少具有Start,BookedById和End列 在此行的第二个查询中,不需要.Select(c => new { c.Key.Day, c.Key.BookedById, Count = c.Count() })

0 个答案:

没有答案