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
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