-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Can't translate GroupBy with Conditional Aggregate #18836
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This was referenced Feb 8, 2020
I have the same problem. var result = Entities
.GroupBy(x => x.UserId)
.Select(g => new
{
UserId = g.Key,
TotalScore1 = g.Sum(x => x.Type == 1 ? x.Score : 0),
TotalScore2 = g.Sum(x => x.Type == 2 ? x.Score : 0)
}); This throws error: 0 ' could not be translated. Current workaround: var result = Entities
.Select(x => new
{
x.UserId,
Score1 = x.Type == 1 ? x.Score : 0,
Score2 = x.Type == 2 ? x.Score : 0
})
.GroupBy(x => x.UserId)
.Select(g => new
{
UserId = g.Key,
TotalScore1 = g.Sum(x => x.Score1),
TotalScore2 = g.Sum(x => x.Score2)
}); It's a little bit messy. |
ghost
pushed a commit
that referenced
this issue
Aug 3, 2020
This issue was closed.
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
this is my Class and code to
now i have a Query like this
the DistributedCustomerCount , WaitingCount , ReadCount is always Equals . maybe the
Conditionals at Count method not Translating.
EF Core version: 3.0
Database provider: (Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (.NET Core 3.0)
Operating system: Windows 10
IDE: (Visual Studio 2019 16.3)
The text was updated successfully, but these errors were encountered: