EF4 with MySql - .Include not working with grouping

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Posts: 6
Joined: Mon 27 Oct 2008 13:57

EF4 with MySql - .Include not working with grouping

Post by notken » 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?

Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 25 Feb 2011 10:27

The first case (query for each entry) is designed behaviour without the Include call.
As for the OUTER APPLY statement, take a look at this discussion, for example.

Post Reply