gpt4 book ai didi

linq - 不支持嵌套查询。操作 1 ='UnionAll' 操作 2 ='MultiStreamNest'

转载 作者:行者123 更新时间:2023-12-02 11:22:30 27 4
gpt4 key购买 nike

我有以下形式的 Linq to Entities 查询:

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);

(这是一个简化的例子 - 'where' 和 'select' 子句比这里显示的更复杂。我使用单独的查询语句,因为创建一个单独的组合语句太复杂了,有太多的条件,需要很长时间才能编译)

编译正常,但执行失败,异常:
"The nested query is not supported. Operation1='UnionAll' Operation2='MultiStreamNest'

请注意,我正在尝试投影到嵌套类型结构中。如果我在 Concat() 之前在 x 和 y 上调用 .ToList() 它工作正常。还有一点,我的一个属性是枚举,但我使用整数包装器属性分配给它。

有没有一种方法可以做我想做的事情而不必将所有数据拉入内存?或者是导致失败的枚举?

谢谢,

最佳答案

你有没有试过

 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
});

关于linq - 不支持嵌套查询。操作 1 ='UnionAll' 操作 2 ='MultiStreamNest',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10138023/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com