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

定義

別のオブジェクト クエリの結果に基づいて結果を除外することで、クエリ結果を制限します。

public:
 System::Data::Objects::ObjectQuery<T> ^ Except(System::Data::Objects::ObjectQuery<T> ^ query);
public System.Data.Objects.ObjectQuery<T> Except(System.Data.Objects.ObjectQuery<T> query);
member this.Except : System.Data.Objects.ObjectQuery<'T> -> System.Data.Objects.ObjectQuery<'T>
Public Function Except (query As ObjectQuery(Of T)) As ObjectQuery(Of T)

パラメーター

query
ObjectQuery<T>

クエリから除外する結果を表す ObjectQuery<T>

返品

指定したqueryに基づいて EXCEPT が適用された元のインスタンスと同等の新しいObjectQuery<T> インスタンス。

例外

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

この例では、 Except メソッドを使用して新しい ObjectQuery<T> オブジェクトを作成し、新しいクエリの結果を反復処理します。

int productID = 900;
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString = @"SELECT VALUE product
        FROM AdventureWorksEntities.Products AS product";

    ObjectQuery<Product> productQuery =
        new ObjectQuery<Product>(queryString,
            context, MergeOption.NoTracking);

    string queryString2 = @"SELECT VALUE product
        FROM AdventureWorksEntities.Products
        AS product WHERE product.ProductID < @productID";

    ObjectQuery<Product> productQuery2 =
        new ObjectQuery<Product>(queryString2,
            context, MergeOption.NoTracking);

    productQuery2.Parameters.Add(new ObjectParameter("productID", productID));

    ObjectQuery<Product> productQuery3 =
        productQuery.Except(productQuery2);

    Console.WriteLine("Result of Except");
    Console.WriteLine("------------------");

    // Iterate through the collection of Product items
    // after the Except method was called.
    foreach (Product result in productQuery3)
        Console.WriteLine("Product Name: {0}",
            result.ProductID);
}

注釈

除外する結果を定義する指定された query は、同じ型であるか、 ObjectQuery<T>と互換性のある型である必要があります。

指定された query で定義されているパラメーターは、 ObjectQuery<T> インスタンスで定義されているパラメーターとマージされます。 パラメーターは、結合された ObjectParameterCollectionで一意である必要があります。 同じ名前の結合コレクションに 2 つのパラメーターを指定することはできません。 詳細については、「 クエリ ビルダーメソッド」を参照してください。

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

適用対象

こちらもご覧ください