【发布时间】:2012-04-13 09:01:57
【问题描述】:
我有一个如下形式的 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() 它工作正常。另外一点,我的属性之一是枚举,但我使用整数包装器属性对其进行分配。
有没有一种方法可以做我想做的事而不必将所有数据拉入内存?还是枚举导致失败?
谢谢,
T
【问题讨论】:
标签: linq entity-framework