Query: Entity Framework core 1 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
{
group.Key,
Total = group.Count()
}).Take(10)
.ToList();
Does anyone faced with this problem?
Is there an ETA on this? I have the same exception, and I have to call ToArray() before filtering, which obviously is bad for performances.
It's on our list to investigate for the next release (1.2.0). Once we understand the work required, we'll have a better idea of where this fits.
This still reproduces on current bits. We generate the following query plan:
(QueryContext queryContext) => IEnumerable<<>f__AnonymousType0<int, int>> _InterceptExceptions(
source: IEnumerable<<>f__AnonymousType0<int, int>> _Select(
source: IEnumerable<IGrouping<int, ForumPost>> Take(
source: IEnumerable<IGrouping<int, ForumPost>> _GroupBy(
source: IEnumerable<ForumPost> Union(
first: IEnumerable<ForumPost> _ShapedQuery(
queryContext: queryContext,
shaperCommandContext: SelectExpression:
SELECT [e1].[ForumPostId], [e1].[Deleted], [e1].[ForumTopicId], [e1].[Message]
FROM [ForumPosts] AS [e1]
WHERE [e1].[Deleted] = 1,
shaper: BufferedEntityShaper<ForumPost>),
second: IEnumerable<ForumPost> _ShapedQuery(
queryContext: queryContext,
shaperCommandContext: SelectExpression:
SELECT [e2].[ForumPostId], [e2].[Deleted], [e2].[ForumTopicId], [e2].[Message]
FROM [ForumPosts] AS [e2]
WHERE [e2].[Deleted] = 0,
shaper: BufferedEntityShaper<ForumPost>)),
keySelector: (ForumPost e) => ---> [e] <--- .ForumTopicId,
elementSelector: (ForumPost e) => ---> [e] <--- ),
count: int GetParameterValue(
queryContext: queryContext,
parameterName: "__p_0")),
selector: (IGrouping<int, ForumPost> group) => new <>f__AnonymousType0<int, int>(
group.Key,
int Count(group)
)),
contextType: Repro6658.MyContext,
logger: SensitiveDataLogger<IQueryCompilationContextFactory>,
queryContext: queryContext)
Which node is non-reducible?
key selector and element selector on the GroupBy, updated the query plan with debug version instead
So is this problem solved?
Re-opening to add more coverage for set operations and group by interactions.
Filed #17607 for further test coverage.