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.