markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 303 forks source link

InMemoryAdapter group by with count behaviour differs from real result #258

Open davidoleary opened 11 years ago

davidoleary commented 11 years ago

When using group by with a count with the InMemoryAdapter the result is different to production db.

Example:
wrapper class: class Region { public string RegionName { get; set; } public string Count { get; set; } }

var adapter = new InMemoryAdapter(); Database.UseMockAdapter(adapter);

var db = Database.Open(); db.ParentRegionList.Insert(Id: 1, RegionName: "Dublin"); db.ParentRegionList.Insert(Id: 2, RegionName: "Atlanta"); db.ParentRegionList.Insert(Id: 3, RegionName: "Atlanta"); db.ParentRegionList.Insert(Id: 4, RegionName: "Killarney"); db.ParentRegionList.Insert(Id: 5, RegionName: "bournemouth");

var result = db.ParentRegionList.All() .Select(db.ParentRegionList.RegionName, db.ParentRegionList.RegionName.Count().As("Count")) .Where(db.ParentRegionList.RegionName.Like("At%")) .Take(10).ToScalarList();

In SQL Profiler the following SQL is executed: select TOP 10 [BookingSite].[ParentRegionList].[RegionName], Count([BookingSite].[ParentRegionList].[RegionName]) from [BookingSite].[ParentRegionList] WHERE [BookingSite].[ParentRegionList].[RegionName] LIKE 'At%' GROUP BY [BookingSite].[ParentRegionList].[RegionName]

Which result in: RegionName Count Atlanta 2

When run against the InMemoryAdapter the result is: RegionName Count Atlanta Atlanta
Atlanta Atlanta

markrendle commented 11 years ago

Argh, this has been hiding behind one of the filters.

I'll have a look at this, but the stock answer in situations like this is "if InMemoryAdapter doesn't work, use SQLite InMem"