public static void GroupBy_SQL_NonEntityType() { // Get the number of flights per Departure using (var ctx = new WWWingsContext()) { // Map SQL to non-entity class Console.WriteLine(ctx.Database.GetType().FullName); ctx.Log(); var sql = "SELECT Departure, COUNT(FlightNo) AS FlightCount FROM Flight GROUP BY Departure"; // ERROR!!! Cannot create a DbSet for 'Group' because this type is not included in the model for the context." var groupSet = ctx.Query <DepartureGroup>().FromSql(sql); // Output foreach (var g in groupSet) { Console.WriteLine(g.Departure + ": " + g.FlightCount); } } return; // Groupy by "nested" using (var ctx = new WWWingsContext()) { ctx.Log(); var groupSet = from p in ctx.FlightSet orderby p.FreeSeats group p by p.Departure into g select g; Console.WriteLine("Count: " + groupSet.Count()); foreach (var g in groupSet) { Console.WriteLine(g.Key + ": " + g.Count()); foreach (var f in g) { Console.WriteLine(" " + f.FlightNo); } } } }