Nested query is not supported. Operation1 = 'UnionAll' Operation2 = 'MultiStreamNest'

I have a Linq to Entities query like this:

var x = from a in SomeData
    where ... some conditions ...
    select new MyType
    {
        Property = a.Property,
        ChildCollection = from b in a.Children
                        select new MyChildType
                        {
                            SomeProperty = b.Property,
                            AnotherProperty = b.AnotherProperty
                        }
    };

var y = from a in SomeData
    where ... some other conditions ...
    select new MyType
    {
        Property = a.Property,
        ChildCollection = from b in a.Children
                        select new MyChildType
                        {
                            SomeProperty = b.Property,
                            AnotherProperty = b.AnotherProperty
                        }
    };

var results = x.Concat(y);

(This is a simplified example - the where and select clauses are more complex than shown here. I use separate query queries because creating one combined query is just too complicated, has too many conventions, and takes age to compile)

It compiles normally, but fails when executed with the exception of:

"The nested query is not supported. Operation1='UnionAll' Operation2='MultiStreamNest'

Notice I'm trying to project into a nested typed structure. If I call .ToList () on x and y before Concat (), it works fine. As another point, one of my properties is an enumeration, but I assign it using the integer shell property.

, , , ? , ?

,

+5
3

 var results = x.Union(y);

?

var x = (from a in SomeData
where ... some conditions ...
select new MyType
{
    Property = a.Property,
    ChildCollection = (from b in a.Children
                    select new MyChildType
                    {
                        SomeProperty = b.Property,
                        AnotherProperty = b.AnotherProperty
                    }).ToArray() //or DefaultIfEmpty
}).Concat(
from a in SomeData
where ... some other conditions ...
select new MyType
{
    Property = a.Property,
    ChildCollection = (from b in a.Children
                    select new MyChildType
                    {
                        SomeProperty = b.Property,
                        AnotherProperty = b.AnotherProperty
                    }).ToArray() //or DefaultIfEmpty
});
0

, IEnumerable, :

var requiredDocuments =                
                 (from x in db.RequestTypes where (some condition) select x.RequiredDocuments)
                 .SelectMany(r => r).ToList<DataModel.RequiredDocument>()
                 .Concat(
                 (from c in db.Categories where (some condition) select c.RequiredDocuments)
                 .SelectMany(r => r).ToList<DataModel.RequiredDocument>()
                 )
                 .Concat(
                 (from f in db.Fields where (some condition) select f.RequiredDocuments)
                 .SelectMany(r => r).ToList<DataModel.RequiredDocument>()
                );
0

If I understand correctly what you are trying to do, I encountered the same problem several times. The bottom line is that joins with nested projections are not supported, and if you need to do this, you first need to materialize the results using ToList.

0
source

All Articles