ObjectQuery<T>.Except(ObjectQuery<T>) Método

Definição

Limita os resultados da consulta excluindo resultados com base nos resultados de outra consulta de objeto.Limits the query results by excluding results based on the results of another object query.

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)

Parâmetros

query
ObjectQuery<T>

Um ObjectQuery<T> que representa os resultados excluídos da consulta.An ObjectQuery<T> that represents the results to exclude from the query.

Retornos

Uma nova instância ObjectQuery<T> que é equivalente à instância original com EXCEPT aplicado com base no query especificado.A new ObjectQuery<T> instance that is equivalent to the original instance with EXCEPT applied based on the specified query.

Exceções

O parâmetro query é null ou uma cadeia de caracteres vazia.The query parameter is null or an empty string.

Exemplos

Este exemplo é baseado no Microsoft SQL Server exemplos de produto: banco de dados.This example is based on the Microsoft SQL Server Product Samples: Database. O exemplo usa Except método para criar um novo objeto de ObjectQuery<T> e, em seguida, itera por meio do resultado da nova consulta.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 =
        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);
}
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")
    Console.WriteLine("------------------")

    ' 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)
    Next
End Using

Comentários

O query fornecido que define os resultados a serem excluídos deve ser do mesmo tipo ou de um tipo compatível com o 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>.

Os parâmetros definidos no query fornecido são mesclados com parâmetros que são definidos na instância de ObjectQuery<T>.Parameters that are defined in the supplied query are merged with parameters that are defined in the ObjectQuery<T> instance. Os parâmetros devem ser exclusivos no ObjectParameterCollectioncombinado.Parameters must be unique in the combined ObjectParameterCollection. Não pode haver dois parâmetros na coleção combinada com o mesmo nome.There cannot be two parameters in the combined collection with the same name. Para obter mais informações, consulte métodos de construtor de consultas.For more information, see Query Builder Methods.

A consulta resultante herda a conexão da instância de ObjectQuery<T> na qual Except foi chamado.The resulting query inherits the connection from the ObjectQuery<T> instance on which Except was called.

Aplica-se a

Veja também