ObjectQuery<T>.Intersect(ObjectQuery<T>) メソッド

定義

別のオブジェクト クエリに存在する結果のみを含めることで、クエリの結果を制限します。

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>

戻り値

指定された query に基づいて INTERSECT が適用された元のインスタンスに相当する、新しい ObjectQuery<T> インスタンス。

例外

query パラメーターが null または空の文字列です。

この例では、他の 2 つのクエリの結果を含む 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 内で一意である必要があります。 結合されたコレクション内に同じ名前のパラメーターが 2 つ存在することはできません。 詳細については、「 Query Builder メソッド」を参照してください。

結果のクエリは、ObjectQuery<T> メソッドが呼び出された Intersect インスタンスから接続を継承します。

適用対象

こちらもご覧ください