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

Each GROUP BY expression must contain at least one column that is not an outer reference #346

Open
croban opened this issue Mar 4, 2015 · 2 comments

Comments

@croban
Copy link

croban commented Mar 4, 2015

Group by constant value is not possible e.g.

var query = from cc in Repo.AsQueryable()
group cc by 1 into g
select new {
MinLogId=g.Min(f=>f.Id),
MaxLogId=g.Max(f=>f.Id),
}

throws Operation 'ExecuteReader' throws exception 'BLToolkit.Data.DataException: Each GROUP BY expression must contain at least one column that is not an outer reference.

@ili
Copy link
Collaborator

ili commented Mar 5, 2015

What Sql are you expecting?
for ex. for MSSQL query

select max(ParentId), max(ChildId)
from Child
group by 1

raise error - Group by should contain at least one field

If you do need just min & max you can do:

cc.Select(_ => (int?)_.Id).Max();

@croban
Copy link
Author

croban commented Mar 5, 2015

Hi ili

expected query should be:
select min(LogId), max(LogId) from Archive

without grouping statement.

There is also need for example for Summing more then one value over the whole table:
select Sum(IsNew), Sum(IsOpen), Sum(IsClosed) from something

As you have proposed is an workaround which I am already using just that are two queries on DB resp. more than one if more columns are needed.

br.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants