igor-tkachev / bltoolkit

Business Logic Toolkit for .NET
MIT License
297 stars 113 forks source link

Bad grouping code generation #332

Closed Firebie closed 9 years ago

Firebie commented 10 years ago
create table Item
(
  Id int not null,
  Data int,

  constraint PkItems primary key (Id)
)
class Item
{
  public int  Id;
  public int? Data;
}

using (var db = new DbManager())
{
  var data = db.GetTable<Item>().GroupBy(i => 0).Select(i => new { Min = i.Min(j => j.Data), Max = i.Max(j => j.Data) }).FirstOrDefault();
}

Expected sql:

SELECT MIN(Item.Data), MAX(Item.Data)
FROM (SELECT 0 AS Id, Data FROM Item) AS Item
GROUP BY Item.Id

Generated sql (bad):

SELECT TOP 1
    Min([selectParam].[Data]) as [c1],
    Max([selectParam].[Data]) as [c2]
FROM
    [Item] [selectParam]
GROUP BY
    0