EF4 with MySql - .Include not working with grouping
Posted: Thu 24 Feb 2011 16:15
Hi there. I'm using Devart MySql EF on a complex model on a new MVC 3 Web site. Generally all is fine, but I'm publishing a page of release dates for videogames.
Existing filters and functions are creating an IQueryable collection of release dates that can be seen by the current user based on their admin status, region, etc.
The penultimate step in building the query is to group the set of schedule entries (with a foreign relationship to a product and another to a format) so that it collates by product and release date (so instead of 3 entries for a game on 3 formats all coming out the same day, it's shown as one entry with one release date and three formats).
This is done with:
from s in scheduleEntries
group s by new {ProductId = s.Product.Id, s.DisplayDate}
into grp
select new ScheduleGroup
{
ProductId = grp.Key.ProductId,
DisplayDate = grp.Key.DisplayDate,
ScheduleEntries = grp.Distinct()
};
This works fine as a query, and produces the result I need. (I use automapper to convert the enumeration of ScheduleGroups into a view model, flattening all but the formats, which are a list in this view model.)
But the problem is that despite the initial query of scheduleEntries having .Includes for the foreign tables, dbMonitor is showing that it is still making a query per schedule entry, fetching each product and each format.
I tried adding the .Includes into this group query, after scheduleEntries, but then I get an error:
OUTER APPLY is not supported by MySQL
I'm not sure how to access the command string that's generated. dbMonitor won't show it if it throws an error.
Any advice?
Existing filters and functions are creating an IQueryable collection of release dates that can be seen by the current user based on their admin status, region, etc.
The penultimate step in building the query is to group the set of schedule entries (with a foreign relationship to a product and another to a format) so that it collates by product and release date (so instead of 3 entries for a game on 3 formats all coming out the same day, it's shown as one entry with one release date and three formats).
This is done with:
from s in scheduleEntries
group s by new {ProductId = s.Product.Id, s.DisplayDate}
into grp
select new ScheduleGroup
{
ProductId = grp.Key.ProductId,
DisplayDate = grp.Key.DisplayDate,
ScheduleEntries = grp.Distinct()
};
This works fine as a query, and produces the result I need. (I use automapper to convert the enumeration of ScheduleGroups into a view model, flattening all but the formats, which are a list in this view model.)
But the problem is that despite the initial query of scheduleEntries having .Includes for the foreign tables, dbMonitor is showing that it is still making a query per schedule entry, fetching each product and each format.
I tried adding the .Includes into this group query, after scheduleEntries, but then I get an error:
OUTER APPLY is not supported by MySQL
I'm not sure how to access the command string that's generated. dbMonitor won't show it if it throws an error.
Any advice?