Group By after Union throw "must be reducible node" Exception



I need unoin two query and after union Group By that, but throw "must be reducible node" Exception. in following sample code are:

public class ForumPost
    public int ForumPostId { get; set; }
    public string Message { get; set; }
    public bool Deleted { get; set; }
    public int ForumTopicId { get; set; }
    public virtual ForumTopic ForumTopic { get; set; }

var query1 = _dbContext.ForumPosts
    .Where(e => e.Deleted == true);

var query2 = _dbContext.ForumPosts
    .Where(e => e.Deleted == false);

var query =  query1.Union(query2);

var list = query.GroupBy(e => e.ForumTopicId)
    .Select(group => new
        Total = group.Count()

Does anyone faced with this problem?

10/2/2016 4:14:19 PM

Accepted Answer

I guess this special case wasn't enabled, but when you take a look at the EntityFramework Core Roadmap, you'll see in the "Critical O/RM Features" the following entries:

Critical O/RM features

The things we think we need before we say EF Core is the recommended version of EF. Until we implement these features EF Core will be a valid option for many applications, especially on platforms such as UWP and .NET Core where EF6.x does not work, but for many applications the lack of these features will make EF6.x a better option.


  • Improved translation will enable more queries to successfully execute, with more logic being evaluated in the database (rather than in-memory).
  • GroupBy translation will move translation of the LINQ GroupBy operator to the database, rather than in-memory.

So you won't lose much if, as a workaround, you fetch the data from the Union Query (i.e. doing a .ToList() or .AsEnuberable() on it) and the perform the GroupBy on the in memory data until the two features are implemented.

As far as I know, EntityFramework Core 1.1 is scheduled for Q4 2016 - Q1/2017, so you either wait or do the workaround, depending on the deadline of your project.

If I remember correctly Rowan Miller mentioned they want to keep the releases in sync with ASP.NET Core 1.1 which is also scheduled for Fall 2016 and that there is no technical reason (i.e. a feature which requires ASP.NET Core 1.1) for doing this, but for now it's in sync with ASP.NET Core but may or may not get it's own independent release cycles in future.

Or if you're very brave and your Web application isn't production ready yet, you could try the nightly builds.

10/2/2016 10:12:13 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow