bltoolkit icon indicating copy to clipboard operation
bltoolkit copied to clipboard

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

Open croban opened this issue 10 years ago • 2 comments

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.

croban avatar Mar 04 '15 15:03 croban

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();

ili avatar Mar 05 '15 06:03 ili

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.

croban avatar Mar 05 '15 10:03 croban