How can I do a Union all in Entity Framework LINQ

2019-02-16 04:30发布

I came across a scenario where I had to use Union all, how can I achieve so in LINQ to entities ?

2条回答
劫难
2楼-- · 2019-02-16 04:56

Here is the answer you are looking for. Use the Concat keyword.

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} );
查看更多
不美不萌又怎样
3楼-- · 2019-02-16 05:02

I believe Concat is what you're looking for.

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.

查看更多
登录 后发表回答