Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL generation issue when doing a SUM with a column Coalesce function in it #7428

Closed
Tratcher opened this issue Jan 17, 2017 · 1 comment
Closed

Comments

@Tratcher
Copy link
Member

From @grantnilsson on January 16, 2017 22:57

I have a class (called Transaction), which has a property defined as a nullable integer (int?). I then run a Linq command against this property to SUM all the values together. Note: some transactions have a NULL vaue for this field.

public class Transaction
{
    ...
    int? numberOfUnits {get; set;}
    ...
}

The Linq command looks like this

_context.Transactions
    .Sum(x => x.NumberOfUnits ?? 0);

This generates an invalid SQL command stating "'sum' is not a recognized built-in function name.". This is because the generated SQL is invalid. The SQL generated is as follows:

SELECT sum(COALESCE([x].[NumberOfUnits], 0) AS [Coalesce])
FROM Transaction AS [x]

NOTE: the issue is actually the fact that the coalesce generates an alias for itself. NO alias should be generated for the Coalesce at all

Copied from original issue: dotnet/aspnetcore#1901

@smitpatel
Copy link
Member

duplicate of #7103 fixed in dev.

@divega divega removed the type-bug label May 8, 2017
@divega divega removed this from the 2.0.0-preview1 milestone May 8, 2017
@smitpatel smitpatel removed their assignment Jan 12, 2022
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants