Tim*_*don 6 linq entity-framework
我有以下形式的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);
Run Code Online (Sandbox Code Playgroud)
(这是一个简化的例子 - 'where'和'select'子句比这里显示的更复杂.我使用单独的查询语句,因为创建单个组合的语句太复杂,有太多的条件并需要一个年龄编译)
编译正常,但在执行时失败,异常:
"The nested query is not supported. Operation1='UnionAll' Operation2='MultiStreamNest'
Run Code Online (Sandbox Code Playgroud)
注意,我试图投射到嵌套的类型结构.如果我在Concat()之前在x和y上调用.ToList()它可以正常工作.另外一点,我的一个属性是枚举,但是我使用整数包装器属性来分配它.
有没有办法我可以做我想做的事情,而不必将所有数据都拉入内存?或者是导致失败的枚举?
谢谢,
Ť
你有没有尝试过
var results = x.Union(y);
Run Code Online (Sandbox Code Playgroud)
?
提兹
或者
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
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4136 次 |
最近记录: |