I'm trying to perform a group by and then a join after (based on what other posts here suggested) and i'm getting the following error in .NET 5
'RelationalProjectionBindingExpressionVisitor' failed. This may indicate either a bug or a limitation in Entity Framework.
code:
var test = (from ra in _db.ResourceAllocation
group ra by new { ra.Date, ra.ResourceId } into g
join resource in _db.Resource on g.Key.ResourceId equals resource.Id
select new
{
ResourceName = resource.Name,
ResourceDayOfWeek = resource.DayOfWeek,
g.Key.Date,
userSum = g.Sum(x => x.userCount)
}).OrderByDescending(e => e.Date).ToList();
Try to simplify life for LINQ Translator and separate queries by parts. This query should be translatable:
var grouped =
from ra in _db.ResourceAllocation
group ra by new { ra.Date, ra.ResourceId } into g
select new
{
g.Key.Date,
g.Key.ResourceId,
userSum = g.Sum(x => x.userCount)
}
var query =
from g in grouped
join resource in _db.Resource on g.ResourceId equals resource.Id
select new
{
ResourceName = resource.Name,
ResourceDayOfWeek = resource.DayOfWeek,
g.Date,
g.userSum
);
var result = query.OrderByDescending(e => e.Date).ToList();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.