2017-01-05 5 views
0

Я хотел бы преобразовать следующий SQL запрос в LINQ к Сущности версии:LINQ к Entities - Как конвертировать SQL запрос (UnionAggregate) в LINQ

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 
+0

http://stackoverflow.com/questions/8394111/how-to-convert-sql-query-with-unions-to-linq – FakeisMe

+0

Смотрите MSDN: https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b – jdweng

+0

@FakeisMe То, что я пытаюсь сделать, это UnionAggregate of SqlGeometries, а не Union of raws, спасибо. – antobonfiglio

ответ

0

В LINQ союз функциональны обеспечивается 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));