sách gpt4 ai đã đi

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

In lại 作者:行者123 更新时间:2023-12-02 11:22:30 28 4
mua khóa gpt4 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() 它工作正常。还有一点,我的一个属性是枚举,但我使用整数包装器属性分配给它。

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

谢谢,

1 Câu trả lời

你有没有试过

 var results = x.Union(y);

?

蒂兹

hoặc
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/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com