You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
await _context.Users
.Include(s => s.Categories)
.Select(s => new
{
Id = s.Id,
Name = s.Name,
PointsTotal = s.Categories.Sum(u => u.Points)
})
.OrderByDescending(e => e.PointsTotal)
.ToListAsync();
A user has many categories where he can get points, and for leader board purposes I want to get the sum of the points he has.
Linq to SQL does translate the statement, however it is not optimal:
Provided:
SELECT [s0].[Id] AS [Id], [s0].[Name] AS [Name], (
SELECT SUM([s].[Points])
FROM [UserCategories] AS [s]
WHERE [s0].[Id] = [s].[UserId]) AS [PointsTotal]
FROM [Users] AS [s0]
ORDER BY (
SELECT SUM([s1].[Points])
FROM [UserCategories] AS [s1]
WHERE [s0].[Id] = [s1].[UserId]) DESC
Expected:
SELECT [s0].[Id] AS [Id], [s0].[Name] AS [Name], (
SELECT SUM([s].[Points])
FROM [UserCategories] AS [s]
WHERE [s0].[Id] = [s].[UserId]) AS [PointsTotal]
FROM [Users] AS [s0]
ORDER BY [PointsTotal] DESC
Using Microsoft.EntityFrameworkCore.SqlServer 3.1.0 package
The text was updated successfully, but these errors were encountered:
Consider the following LINQ code:
A user has many categories where he can get points, and for leader board purposes I want to get the sum of the points he has.
Linq to SQL does translate the statement, however it is not optimal:
Provided:
Expected:
Using Microsoft.EntityFrameworkCore.SqlServer 3.1.0 package
The text was updated successfully, but these errors were encountered: