LINQ to Entities - 如何将SQL查询(UnionAggregate)转换为LINQ

时间:2017-01-05 12:33:27

标签: c# sql-server linq-to-sql spatial-query

我想将LINQ中的以下SQL查询转换为实体版本:

select
 geometry::UnionAggregate(geometries.GeometryBounds) 
from 
( select 
    GeometryBounds
  from 
    Province where id in ( 1, 2 )
  union all
  select 
    GeometryBounds
  from 
    Region where id in ( 1, 2 )
  union all
  select 
    GeometryBounds
  from 
    Country where id in ( 1, 2 ) 
) as geometries

1 个答案:

答案 0 :(得分:0)

在LINQ union中,所有函数都由Collection.Concat()方法提供。

var ID = new[] {1, 2};

var query = (youContext.Province
            .Select(x => x.GeometryBounds))
            .Concat
            (youContext.Region
            .Select(x => x.GeometryBounds))
            .Concat
            (youContext.Country
            .Select(x => x.GeometryBounds));
相关问题