Udostępnij za pośrednictwem


Queryable.ThenBy Metoda

Definicja

Wykonuje kolejność elementów w kolejności rosnącej.

Przeciążenia

Nazwa Opis
ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>)

Wykonuje kolejność elementów w kolejności rosnącej przy użyciu określonego modułu porównującego.

ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>)

Wykonuje kolejność elementów w kolejności rosnącej zgodnie z kluczem.

ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>)

Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs

Wykonuje kolejność elementów w kolejności rosnącej przy użyciu określonego modułu porównującego.

public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IOrderedQueryable<TSource> ^ ThenBy(System::Linq::IOrderedQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TKey> ^> ^ keySelector, System::Collections::Generic::IComparer<TKey> ^ comparer);
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IComparer<TKey> comparer);
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IComparer<TKey>? comparer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector, System.Collections.Generic.IComparer<TKey>? comparer);
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> * System.Collections.Generic.IComparer<'Key> -> System.Linq.IOrderedQueryable<'Source>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> * System.Collections.Generic.IComparer<'Key> -> System.Linq.IOrderedQueryable<'Source>
<Extension()>
Public Function ThenBy(Of TSource, TKey) (source As IOrderedQueryable(Of TSource), keySelector As Expression(Of Func(Of TSource, TKey)), comparer As IComparer(Of TKey)) As IOrderedQueryable(Of TSource)

Parametry typu

TSource

Typ elementów elementu source.

TKey

Typ klucza zwróconego przez funkcję reprezentowaną przez keySelectorelement .

Parametry

source
IOrderedQueryable<TSource>

Element IOrderedQueryable<T> zawierający elementy do sortowania.

keySelector
Expression<Func<TSource,TKey>>

Funkcja wyodrębniania klucza z każdego elementu.

comparer
IComparer<TKey>

Element IComparer<T> do porównywania kluczy.

Zwraca

Element IOrderedQueryable<T> , którego elementy są sortowane według klucza.

Atrybuty

Wyjątki

source lub keySelectorcomparer ma wartość null.

Uwagi

Ta metoda ma co najmniej jeden parametr typu Expression<TDelegate> , którego argument type jest jednym z Func<T,TResult> typów. W przypadku tych parametrów można przekazać wyrażenie lambda i zostanie skompilowane do elementu Expression<TDelegate>.

Metoda ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) generuje obiekt MethodCallExpression , który reprezentuje wywołanie ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) jako skonstruowaną metodę ogólną. Następnie przekazuje MethodCallExpression wartość do CreateQuery<TElement>(Expression) metody IQueryProvider reprezentowanej przez Provider właściwość parametru source . Wynik wywołania CreateQuery<TElement>(Expression) jest rzutowany na typ IOrderedQueryable<T> i zwracany.

Zachowanie zapytania, które występuje w wyniku wykonania drzewa wyrażeń reprezentującego wywołanie ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>, IComparer<TKey>) , zależy od implementacji typu parametru source . Oczekiwane zachowanie polega na tym, że wykonuje pomocniczy rodzaj elementów source opartych na kluczu uzyskanym przez wywołanie keySelector każdego elementu elementu source. Wszystkie wcześniej ustanowione zamówienia sortowania są zachowywane. Parametr comparer służy do porównywania wartości kluczy.

Dotyczy

ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>)

Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs
Źródło:
Queryable.cs

Wykonuje kolejność elementów w kolejności rosnącej zgodnie z kluczem.

public:
generic <typename TSource, typename TKey>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IOrderedQueryable<TSource> ^ ThenBy(System::Linq::IOrderedQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TKey> ^> ^ keySelector);
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IOrderedQueryable<TSource> ThenBy<TSource,TKey>(this System.Linq.IOrderedQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TKey>> keySelector);
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> -> System.Linq.IOrderedQueryable<'Source>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member ThenBy : System.Linq.IOrderedQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Key>> -> System.Linq.IOrderedQueryable<'Source>
<Extension()>
Public Function ThenBy(Of TSource, TKey) (source As IOrderedQueryable(Of TSource), keySelector As Expression(Of Func(Of TSource, TKey))) As IOrderedQueryable(Of TSource)

Parametry typu

TSource

Typ elementów elementu source.

TKey

Typ klucza zwróconego przez funkcję reprezentowaną przez keySelectorelement .

Parametry

source
IOrderedQueryable<TSource>

Element IOrderedQueryable<T> zawierający elementy do sortowania.

keySelector
Expression<Func<TSource,TKey>>

Funkcja wyodrębniania klucza z każdego elementu.

Zwraca

Element IOrderedQueryable<T> , którego elementy są sortowane według klucza.

Atrybuty

Wyjątki

source lub keySelector ma wartość null.

Przykłady

W poniższym przykładzie kodu pokazano, jak wykonać ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) kolejność pomocniczą elementów w sekwencji.

string[] fruits = { "grape", "passionfruit", "banana", "apple",
                      "orange", "raspberry", "mango", "blueberry" };

// Sort the strings first by their length and then
// alphabetically by passing the identity selector function.
IEnumerable<string> query =
    fruits.AsQueryable()
    .OrderBy(fruit => fruit.Length).ThenBy(fruit => fruit);

foreach (string fruit in query)
    Console.WriteLine(fruit);

/*
    This code produces the following output:

    apple
    grape
    mango
    banana
    orange
    blueberry
    raspberry
    passionfruit
*/
Dim fruits() As String = _
    {"grape", "passionfruit", "banana", "mango", _
     "orange", "raspberry", "apple", "blueberry"}

' Sort the strings first by their length and then 
' alphabetically by passing the identity selector function.
Dim query = fruits.AsQueryable() _
    .OrderBy(Function(fruit) fruit.Length).ThenBy(Function(fruit) fruit)

' Display the results.
Dim output As New System.Text.StringBuilder
For Each fruit As String In query
    output.AppendLine(fruit)
Next
MsgBox(output.ToString())

'This code produces the following output:

'apple
'grape
'mango
'banana
'orange
'blueberry
'raspberry
'passionfruit

Uwagi

Ta metoda ma co najmniej jeden parametr typu Expression<TDelegate> , którego argument type jest jednym z Func<T,TResult> typów. W przypadku tych parametrów można przekazać wyrażenie lambda i zostanie skompilowane do elementu Expression<TDelegate>.

Metoda ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) generuje obiekt MethodCallExpression , który reprezentuje wywołanie ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) jako skonstruowaną metodę ogólną. Następnie przekazuje MethodCallExpression wartość do CreateQuery<TElement>(Expression) metody IQueryProvider reprezentowanej przez Provider właściwość parametru source . Wynik wywołania CreateQuery<TElement>(Expression) jest rzutowany na typ IOrderedQueryable<T> i zwracany.

Zachowanie zapytania, które występuje w wyniku wykonania drzewa wyrażeń reprezentującego wywołanie ThenBy<TSource,TKey>(IOrderedQueryable<TSource>, Expression<Func<TSource,TKey>>) , zależy od implementacji typu parametru source . Oczekiwane zachowanie polega na tym, że wykonuje pomocniczy rodzaj elementów source opartych na kluczu uzyskanym przez wywołanie keySelector każdego elementu elementu source. Wszystkie wcześniej ustanowione zamówienia sortowania są zachowywane.

Dotyczy