Bug #79448 Include unionall issue
Submitted: 30 Nov 2015 3:40 Modified: 30 Nov 2015 5:50
Reporter: epep eppe Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.9.8, EF6 OS:Windows
Assigned to: CPU Architecture:Any

[30 Nov 2015 3:40] epep eppe
Description:
Hi,

I am encountering an issue on our database model, sadly I haven't yet been able to replicate the issue on a simple model I could attach.

We use include force an eager loading on some table.
    model.Ds.Include(x => x.ACs).Include(x => x.Es).Include(x => x.DSs).ToList()

This generates a wrong SQL, the 2 "FROM ((SELECT" : 
    SELECT `UnionAll2`.`Id` AS `C1`, (...)
    FROM ((SELECT
    FROM ((SELECT
    CASE WHEN (`Join1`.`DAC_AC_Id` IS  NULL) THEN (NULL)  ELSE (1) END AS `C1`, (...)

The command tree looks like that:
DbQueryCommandTree
|_Query : Collection{Record['C1'=Edm.Int32, (...)
  |_Project
    |_Input : 'Sort1'
    | |_Sort
    |   |_Input : 'UnionAll2'
    |   | |_UnionAll
    |   |   |_UnionAll
    |   |   | |_Project
    |   |   | |_Project
    |   |   |_Project
    |   |_SortOrder
    |     |_Asc
    |     | |_Var(UnionAll2).Id1
    |     |_Asc
    |       |_Var(UnionAll2).C1
    |_Projection

I believe the 2 UnionAll are source of the issue, the first one not containing 2 Projects

In the SelectGenerator.cs:
    public override SqlFragment Visit(DbUnionAllExpression expression)
    {
      UnionFragment f = new UnionFragment();
      Debug.Assert(expression.Left is DbProjectExpression);
      Debug.Assert(expression.Right is DbProjectExpression);
      (...)

Can Visit(DbUnionAllExpression expression) be patched accordingly ?

Thanks.

How to repeat:
Sadly I haven't yet been able to replicate the issue on a simple model I could attach.
[30 Nov 2015 5:50] Chiranjeevi Battula
Hello epep eppe,

Thank you for the bug report.
This is most likely duplicate of Bug #76466, please see Bug #76466.

Thanks,
Chiranjeevi.