C# 如何在 Entity Framework LINQ To Entities 中进行联合?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9828308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I do a Union all in Entity Framework LINQ To Entities?
提问by Rami Sakr
I came across a scenario where I had to use Union all, how can I achieve so in LINQ to entities ?
我遇到了一个必须使用 Union all 的场景,我如何在 LINQ to entity 中实现它?
采纳答案by Justin Pihony
Here is the answer you are looking for. Use the Concatkeyword.
这是您正在寻找的答案。使用Concat关键字。
From the example:
从示例中:
var query = (from x in db.Table1 select new {A = x.A, B = x.B})
.Concat( from y in db.Table2 select new {A = y.A, B = y.B} );
回答by StriplingWarrior
I believe Concatis what you're looking for.
我相信Concat这就是你要找的。
var allResults = resultSet1.Concat(resultSet2);
Obviously, both result sets must use the same type. And I believe there my be other requirements about how the result sets are constructed in the first place, but I don't know all the details.
显然,两个结果集必须使用相同的类型。而且我相信首先对结果集的构建方式还有其他要求,但我不知道所有细节。

