ObjectQuery<T>.Except(ObjectQuery<T>) 메서드


다른 개체 쿼리의 결과를 기반으로 결과를 제외시켜 쿼리 결과를 제한합니다.Limits the query results by excluding results based on the results of another object query.

 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)

매개 변수


쿼리에서 제외시킬 결과를 나타내는 ObjectQuery<T>입니다.An ObjectQuery<T> that represents the results to exclude from the query.



원래 인스턴스에 지정된 query를 기반으로 EXCEPT가 적용된 것과 동일한 새 ObjectQuery<T> 인스턴스입니다.A new ObjectQuery<T> instance that is equivalent to the original instance with EXCEPT applied based on the specified query.


query 매개 변수가 null이거나 빈 문자열인 경우The query parameter is null or an empty string.


이 예제는 Microsoft SQL Server 제품 샘플: 데이터베이스를 기반으로 합니다.This example is based on the Microsoft SQL Server Product Samples: Database. 이 예제에서는 Except 메서드를 사용 하 여 새 개체를 만든 ObjectQuery<T> 다음 새 쿼리의 결과를 반복 합니다.The example uses Except method to create a new ObjectQuery<T> object and then iterates through the result of the new query.

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 =

    Console.WriteLine("Result of Except");

    // Iterate through the collection of Product items
    // after the Except method was called.
    foreach (Product result in productQuery3)
        Console.WriteLine("Product Name: {0}",
Dim productID = 900
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE product FROM AdventureWorksEntities.Products AS product"
    Dim productQuery As New ObjectQuery(Of Product)(queryString, context, MergeOption.NoTracking)

    Dim queryString2 As String = "SELECT VALUE product FROM AdventureWorksEntities.Products " & _
        " AS product WHERE product.ProductID < @productID"
    Dim productQuery2 As New ObjectQuery(Of Product)(queryString2, context, MergeOption.NoTracking)
    productQuery2.Parameters.Add(New ObjectParameter("productID", productID))

    Dim productQuery3 As ObjectQuery(Of Product) = productQuery.Except(productQuery2)

    Console.WriteLine("Result of Except")

    ' Iterate through the collection of Product items 
    ' after the Except method was called. 
    For Each result As Product In productQuery3
        Console.WriteLine("Product Name: {0}", result.ProductID)
End Using


query제외할 결과를 정의 하는 제공 된는 같은 형식 또는와 호환 되는 형식 이어야 합니다 ObjectQuery<T> .The supplied query that defines results to exclude must be of the same type or of a type that is compatible with the ObjectQuery<T>.

제공 된에 정의 된 매개 변수는 query 인스턴스에 정의 된 매개 변수와 병합 됩니다 ObjectQuery<T> .Parameters that are defined in the supplied query are merged with parameters that are defined in the ObjectQuery<T> instance. 매개 변수는 결합 된에서 고유 해야 합니다 ObjectParameterCollection .Parameters must be unique in the combined ObjectParameterCollection. 결합 된 컬렉션에 같은 이름의 매개 변수가 두 개 있을 수 없습니다.There cannot be two parameters in the combined collection with the same name. 자세한 내용은 쿼리 작성기 메서드합니다.For more information, see Query Builder Methods.

결과 쿼리는가 호출 된 인스턴스에서 연결을 상속 합니다 ObjectQuery<T> Except .The resulting query inherits the connection from the ObjectQuery<T> instance on which Except was called.

적용 대상

추가 정보