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>,它代表要從查詢中排除的結果。

傳回

新的 ObjectQuery<T> 執行個體,其相當於根據指定的 query 套用了 EXCEPT 的原始執行個體。

例外狀況

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 中必須是唯一的。 結合的集合中不能有兩個參數同名。 如需詳細資訊,請參閱 查詢產生器方法

結果查詢會從在上面呼叫 ObjectQuery<T>Except 執行個體繼承連接。

適用於

另請參閱