Queryable.Except Method

Definition

Produz a diferença de conjunto de duas sequências.Produces the set difference of two sequences.

Overloads

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

Produz a diferença de conjunto de duas sequências usando o IEqualityComparer<T> especificado para comparar os valores.Produces the set difference of two sequences by using the specified IEqualityComparer<T> to compare values.

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)

Produz a diferença de conjunto de duas sequências usando o comparador de igualdade padrão para comparar os valores.Produces the set difference of two sequences by using the default equality comparer to compare values.

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

Produz a diferença de conjunto de duas sequências usando o IEqualityComparer<T> especificado para comparar os valores.Produces the set difference of two sequences by using the specified IEqualityComparer<T> to compare values.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ Except(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2, System::Collections::Generic::IEqualityComparer<TSource> ^ comparer);
public static System.Linq.IQueryable<TSource> Except<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource> comparer);
static member Except : System.Linq.IQueryable<'Source> * seq<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Except(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource), comparer As IEqualityComparer(Of TSource)) As IQueryable(Of TSource)

Type Parameters

TSource

O tipo dos elementos das sequências de entrada.The type of the elements of the input sequences.

Parameters

source1
IQueryable<TSource>

Um IQueryable<T> cujos elementos que não estão presentes também no source2 serão retornados.An IQueryable<T> whose elements that are not also in source2 will be returned.

source2
IEnumerable<TSource>

Um IEnumerable<T> cujos elementos que também ocorrem na primeira sequência não aparecerão na sequência retornada.An IEnumerable<T> whose elements that also occur in the first sequence will not appear in the returned sequence.

comparer
IEqualityComparer<TSource>

Um IEqualityComparer<T> para comparar valores.An IEqualityComparer<T> to compare values.

Returns

IQueryable<TSource>

Um IQueryable<T> que contém a diferença de conjunto das duas sequências.An IQueryable<T> that contains the set difference of the two sequences.

Exceptions

source1 ou source2 é null.source1 or source2 is null.

Remarks

O método Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) gera um MethodCallExpression que representa a chamada Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) si mesmo como um método genérico construído.The Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) method generates a MethodCallExpression that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) itself as a constructed generic method. Em seguida, ele passa o MethodCallExpression para o método CreateQuery<TElement>(Expression) do IQueryProvider representado pela propriedade Provider do parâmetrosource1.It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of thesource1 parameter.

O comportamento da consulta que ocorre como resultado da execução de uma árvore de expressão que representa a chamada de Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) depende da implementação do tipo do parâmetro source1.The query behavior that occurs as a result of executing an expression tree that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) depends on the implementation of the type of the source1 parameter. O comportamento esperado é que todos os elementos em source1 são retornados, exceto aqueles que também estão em source2, e comparer é usado para comparar valores.The expected behavior is that all the elements in source1 are returned except for those that are also in source2, and comparer is used to compare values.

Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>)

Produz a diferença de conjunto de duas sequências usando o comparador de igualdade padrão para comparar os valores.Produces the set difference of two sequences by using the default equality comparer to compare values.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TSource> ^ Except(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2);
public static System.Linq.IQueryable<TSource> Except<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2);
static member Except : System.Linq.IQueryable<'Source> * seq<'Source> -> System.Linq.IQueryable<'Source>
<Extension()>
Public Function Except(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource)) As IQueryable(Of TSource)

Type Parameters

TSource

O tipo dos elementos das sequências de entrada.The type of the elements of the input sequences.

Parameters

source1
IQueryable<TSource>

Um IQueryable<T> cujos elementos que não estão presentes também no source2 serão retornados.An IQueryable<T> whose elements that are not also in source2 will be returned.

source2
IEnumerable<TSource>

Um IEnumerable<T> cujos elementos que também ocorrem na primeira sequência não aparecerão na sequência retornada.An IEnumerable<T> whose elements that also occur in the first sequence will not appear in the returned sequence.

Returns

IQueryable<TSource>

Um IQueryable<T> que contém a diferença de conjunto das duas sequências.An IQueryable<T> that contains the set difference of the two sequences.

Exceptions

source1 ou source2 é null.source1 or source2 is null.

Examples

O exemplo de código a seguir demonstra como usar Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) para retornar os elementos que aparecem apenas na primeira sequência de origem.The following code example demonstrates how to use Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) to return those elements that only appear in the first source sequence.

double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 };
double[] numbers2 = { 2.2 };

// Get the numbers from the first array that
// are NOT in the second array.
IEnumerable<double> onlyInFirstSet =
    numbers1.AsQueryable().Except(numbers2);

foreach (double number in onlyInFirstSet)
    Console.WriteLine(number);

/*
    This code produces the following output:

    2
    2.1
    2.3
    2.4
    2.5
*/

Dim numbers1() As Double = {2.0, 2.1, 2.2, 2.3, 2.4, 2.5}
Dim numbers2() As Double = {2.2}

' Get the numbers from the first array that
' are NOT in the second array.
Dim onlyInFirstSet As IEnumerable(Of Double) = _
    numbers1.AsQueryable().Except(numbers2)

Dim output As New System.Text.StringBuilder
For Each number As Double In onlyInFirstSet
    output.AppendLine(number)
Next

' Display the output.
MsgBox(output.ToString())

' This code produces the following output:
'
' 2
' 2.1
' 2.3
' 2.4
' 2.5

Remarks

O método Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) gera um MethodCallExpression que representa a chamada Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) si mesmo como um método genérico construído.The Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method generates a MethodCallExpression that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) itself as a constructed generic method. Em seguida, ele passa o MethodCallExpression para o método CreateQuery<TElement>(Expression) do IQueryProvider representado pela propriedade Provider do parâmetrosource1.It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of thesource1 parameter.

O comportamento da consulta que ocorre como resultado da execução de uma árvore de expressão que representa a chamada de Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) depende da implementação do tipo do parâmetro source1.The query behavior that occurs as a result of executing an expression tree that represents calling Except<TSource>(IQueryable<TSource>, IEnumerable<TSource>) depends on the implementation of the type of the source1 parameter. O comportamento esperado é que todos os elementos em source1 são retornados, exceto aqueles que também estão em source2.The expected behavior is that all the elements in source1 are returned except for those that are also in source2.

Applies to