如何:返回两个序列的并集 (LINQ to SQL)
使用 Union 运算符可返回两个序列的并集。
示例
此示例使用 Union 返回有 Customers 或 Employees 的所有国家/地区的序列。
Dim infoQuery = _
(From cust In db.Customers _
Select cust.Country) _
.Union _
(From emp In db.Employees _
Select emp.Country)
var infoQuery =
(from cust in db.Customers
select cust.Country)
.Union
(from emp in db.Employees
select emp.Country)
;
在 LINQ to SQL 中,Union 运算符是为多重集定义的,定义为多重集的无序串联(实际上是 SQL 中的 UNION ALL 子句的执行结果)。