ObjectQuery<T>.Intersect(ObjectQuery<T>) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
通过仅包括另一个对象查询中存在的结果来限制查询结果。
public:
System::Data::Objects::ObjectQuery<T> ^ Intersect(System::Data::Objects::ObjectQuery<T> ^ query);
public System.Data.Objects.ObjectQuery<T> Intersect(System.Data.Objects.ObjectQuery<T> query);
member this.Intersect : System.Data.Objects.ObjectQuery<'T> -> System.Data.Objects.ObjectQuery<'T>
Public Function Intersect (query As ObjectQuery(Of T)) As ObjectQuery(Of T)
参数
- query
- ObjectQuery<T>
一个 ObjectQuery<T> 表示要包括在查询中的结果。
返回
与基于指定的 queryINTERSECT 应用的原始实例等效的新ObjectQuery<T>实例。
例外
参数 query 为 null 空字符串或为空字符串。
示例
此示例创建一个新 ObjectQuery<T> 对象,该对象包含另外两个查询的结果。
int productID1 = 900;
int productID2 = 950;
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
string queryString = @"SELECT VALUE product
FROM AdventureWorksEntities.Products
AS product WHERE product.ProductID > @productID1";
ObjectQuery<Product> productQuery =
new ObjectQuery<Product>(queryString,
context, MergeOption.NoTracking);
string queryString2 = @"SELECT VALUE product
FROM AdventureWorksEntities.Products
AS product WHERE product.ProductID > @productID2";
ObjectQuery<Product> productQuery2 =
new ObjectQuery<Product>(queryString2,
context, MergeOption.NoTracking);
ObjectQuery<Product> productQuery3 =
productQuery.Intersect(productQuery2);
productQuery3.Parameters.Add(new ObjectParameter("productID1", productID1));
productQuery3.Parameters.Add(new ObjectParameter("productID2", productID2));
Console.WriteLine("Result of Intersect");
Console.WriteLine("------------------");
// Iterate through the collection of Product items
// after the Intersect method was called.
foreach (Product result in productQuery3)
{
Console.WriteLine("Product Name: {0}", result.ProductID);
}
}
注解
提供的 query 用于定义要包含的结果的类型必须与 兼容的 ObjectQuery<T>类型相同或类型。
在提供 query 的参数中定义的参数与实例中 ObjectQuery<T> 定义的参数合并。 参数在组合 ObjectParameterCollection中必须是唯一的。 组合集合中不能有两个具有相同名称的参数。 有关详细信息,请参阅 查询生成器方法。
生成的查询从 ObjectQuery<T> 调用该方法的实例 Intersect 继承连接。