支援與不支援的 LINQ 方法 (LINQ to Entities)Supported and Unsupported LINQ Methods (LINQ to Entities)

本節提供 LINQ to Entities 查詢中支援或不支援的語言整合式查詢 (LINQ) 標準查詢運算子的相關資訊。This section provides information about the Language-Integrated Query (LINQ) standard query operators that are supported or unsupported in LINQ to Entities queries. 許多 LINQ 標準查詢運算子都有一個可接受整數引數的多載版本。Many of the LINQ standard query operators have an overloaded version that accepts an integer argument. 整數引數會對應到序列中以零為基底的索引,此序列中的運算是 IEqualityComparer<T> 、或 IComparer<T>The integer argument corresponds to a zero-based index in the sequence that is being operated on, an IEqualityComparer<T>, or IComparer<T>. 除非另外指定,否則不支援 LINQ 標準查詢運算子的這些多載版本,而且嘗試使用它們將會擲回例外狀況。Unless otherwise specified, these overloaded versions of the LINQ standard query operators are not supported, and attempting to use them will throw an exception.

投影和限制方法Projection and Restriction Methods

LINQ to Entities 查詢中支援大部分的 LINQ 投影和限制方法,但接受位置引數的例外狀況除外。Most of the LINQ projection and restriction methods are supported in LINQ to Entities queries, with the exception of those that accept a positional argument. 如需詳細資訊,請參閱 LINQ to Entities 查詢中的標準查詢運算子For more information, see Standard Query Operators in LINQ to Entities Queries. 下表所列為支援及不支援的投影和限制方法。The following table lists the supported and unsupported projection and restriction methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
Select 支援Supported Function Select(Of TSource, TResult) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> Select<TSource, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector )
Select 不支援Not supported Function Select(Of TSource, TResult) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Integer, TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> Select<TSource, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, int, TResult>> selector )
SelectMany 支援Supported Function SelectMany(Of TSource, TResult) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, IEnumerable(Of TResult))) _ ) As IQueryable(Of TResult) IQueryable<TResult> SelectMany<TSource, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TResult>>> selector )
SelectMany 不支援Not supported Function SelectMany(Of TSource, TResult) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Integer, IEnumerable(Of TResult))) _ ) As IQueryable(Of TResult) IQueryable<TResult> SelectMany<TSource, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, int, IEnumerable<TResult>>> selector )
SelectMany 支援Supported Function SelectMany(Of TSource, TCollection, TResult) ( _ source As IQueryable(Of TSource), _ collectionSelector As Expression(Of Func(Of TSource, IEnumerable(Of TCollection))), _ resultSelector As Expression(Of Func(Of TSource, TCollection, TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> SelectMany\<TSource, TCollection, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, IEnumerable<TCollection>>> collectionSelector, Expression<Func\<TSource, TCollection, TResult>> resultSelector )
SelectMany 不支援Not supported Function SelectMany(Of TSource, TCollection, TResult) ( _ source As IQueryable(Of TSource), _ collectionSelector As Expression(Of Func(Of TSource, Integer, IEnumerable(Of TCollection))), _ resultSelector As Expression(Of Func(Of TSource, TCollection, TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> SelectMany\<TSource, TCollection, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, int, IEnumerable<TCollection>>> collectionSelector, Expression<Func\<TSource, TCollection, TResult>> resultSelector )
Where 支援Supported Function Where(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As IQueryable(Of TSource) IQueryable<TSource> Where<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
Where 不支援Not supported Function Where(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Integer, Boolean)) _ ) As IQueryable(Of TSource) IQueryable<TSource> Where<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, int, bool>> predicate )

聯結方法Join Methods

LINQ to Entities 中支援 LINQ 聯結方法,但 IEqualityComparer 因為比較子無法轉譯成資料來源,所以會接受這些方法。The LINQ join methods are supported in LINQ to Entities, with the exception of those that accept an IEqualityComparer because the comparer cannot be translated to the data source. 如需詳細資訊,請參閱 LINQ to Entities 查詢中的標準查詢運算子For more information, see Standard Query Operators in LINQ to Entities Queries. 下表所列為支援及不支援的聯結方法。The following table lists the supported and unsupported join methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
GroupJoin 支援Supported Function GroupJoin(Of TOuter, TInner, TKey, TResult) ( _ outer As IQueryable(Of TOuter), _ inner As IEnumerable(Of TInner), _ outerKeySelector As Expression(Of Func(Of TOuter, TKey)), _ innerKeySelector As Expression(Of Func(Of TInner, TKey)), _ resultSelector As Expression(Of Func(Of TOuter, IEnumerable(Of TInner), TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>( this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector )
GroupJoin 不支援Not Supported Function GroupJoin(Of TOuter, TInner, TKey, TResult) ( _ outer As IQueryable(Of TOuter), _ inner As IEnumerable(Of TInner), _ outerKeySelector As Expression(Of Func(Of TOuter, TKey)), _ innerKeySelector As Expression(Of Func(Of TInner, TKey)), _ resultSelector As Expression(Of Func(Of TOuter, IEnumerable(Of TInner), TResult)), _ comparer As IEqualityComparer(Of TKey) _ ) As IQueryable(Of TResult) IQueryable<TResult> GroupJoin\<TOuter, TInner, TKey, TResult>( this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func\<TOuter, TKey>> outerKeySelector, Expression<Func\<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, IEnumerable<TInner>, TResult>> resultSelector, IEqualityComparer<TKey> comparer )
Join 支援Supported Function Join(Of TOuter, TInner, TKey, TResult) ( _ outer As IQueryable(Of TOuter), _ inner As IEnumerable(Of TInner), _ outerKeySelector As Expression(Of Func(Of TOuter, TKey)), _ innerKeySelector As Expression(Of Func(Of TInner, TKey)), _ resultSelector As Expression(Of Func(Of TOuter, TInner, TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> Join<TOuter, TInner, TKey, TResult>( this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector )
Join 不支援Not Supported Function Join(Of TOuter, TInner, TKey, TResult) ( _ outer As IQueryable(Of TOuter), _ inner As IEnumerable(Of TInner), _ outerKeySelector As Expression(Of Func(Of TOuter, TKey)), _ innerKeySelector As Expression(Of Func(Of TInner, TKey)), _ resultSelector As Expression(Of Func(Of TOuter, TInner, TResult)), _ comparer As IEqualityComparer(Of TKey) _ ) As IQueryable(Of TResult) IQueryable<TResult> Join\<TOuter, TInner, TKey, TResult>( this IQueryable<TOuter> outer, IEnumerable<TInner> inner, Expression<Func\<TOuter, TKey>> outerKeySelector, Expression<Func\<TInner, TKey>> innerKeySelector, Expression<Func\<TOuter, TInner, TResult>> resultSelector, IEqualityComparer<TKey> comparer )

設定方法Set Methods

LINQ to Entities 查詢中支援大部分的 LINQ set 方法,但使用的方法除外 EqualityComparer<T>Most of the LINQ set methods are supported in LINQ to Entities queries, with the exception of those that use an EqualityComparer<T>. 如需詳細資訊,請參閱 LINQ to Entities 查詢中的標準查詢運算子For more information, see Standard Query Operators in LINQ to Entities Queries. 下表所列為支援及不支援的設定方法。The following table lists the supported and unsupported set methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
All 支援Supported Function All(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As Boolean bool All<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
Any 支援Supported Function Any(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As Boolean bool Any<TSource>( this IQueryable<TSource> source )
Any 支援Supported Function Any(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As Boolean bool Any<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
Contains 支援Supported Function Contains(Of TSource) ( _ source As IQueryable(Of TSource), _ item As TSource _ ) As Boolean bool Contains<TSource>( this IQueryable<TSource> source, TSource item )
Contains 不支援Not supported Function Contains(Of TSource) ( _ source As IQueryable(Of TSource), _ item As TSource, _ comparer As IEqualityComparer(Of TSource) _ ) As Boolean bool Contains<TSource>( this IQueryable<TSource> source, TSource item, IEqualityComparer<TSource> comparer )
Concat 支援,但是不Supported, but there is no

保證會維持排序guarantee of order being preserved
Function Concat(Of TSource) ( _ source1 As IQueryable(Of TSource), _ source2 As IEnumerable(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Concat<TSource>( this IQueryable<TSource> source1, IEnumerable<TSource> source2 )
DefaultIfEmpty 支援Supported Function DefaultIfEmpty(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> DefaultIfEmpty<TSource>( this IQueryable<TSource> source )
DefaultIfEmpty 支援Supported Function DefaultIfEmpty(Of TSource) ( _ source As IQueryable(Of TSource), _ defaultValue As TSource _ ) As IQueryable(Of TSource) IQueryable<TSource> DefaultIfEmpty<TSource>( this IQueryable<TSource> source, TSource defaultValue )
Distinct 支援Supported Function Distinct(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Distinct<TSource>( this IQueryable<TSource> source )
Distinct 不支援Not supported Function Distinct(Of TSource) ( _ source As IQueryable(Of TSource), _ comparer As IEqualityComparer(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Distinct<TSource>( this IQueryable<TSource> source, IEqualityComparer<TSource> comparer )
Except 支援Supported Function Except(Of TSource) ( _ source1 As IQueryable(Of TSource), _ source2 As IEnumerable(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Except<TSource>( this IQueryable<TSource> source1, IEnumerable<TSource> source2 )
Except 不支援Not supported Function Except(Of TSource) ( _ source1 As IQueryable(Of TSource), _ source2 As IEnumerable(Of TSource), _ comparer As IEqualityComparer(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Except<TSource>( this IQueryable<TSource> source1, IEnumerable<TSource> source2, IEqualityComparer<TSource> comparer )
Intersect 支援Supported Function Intersect(Of TSource) ( _ source1 As IQueryable(Of TSource), _ source2 As IEnumerable(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Intersect<TSource>( this IQueryable<TSource> source1, IEnumerable<TSource> source2 )
Intersect 不支援Not supported Function Intersect(Of TSource) ( _ source1 As IQueryable(Of TSource), _ source2 As IEnumerable(Of TSource), _ comparer As IEqualityComparer(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Intersect<TSource>( this IQueryable<TSource> source1, IEnumerable<TSource> source2, IEqualityComparer<TSource> comparer )
Union 支援Supported Function Union(Of TSource) ( _ source1 As IQueryable(Of TSource), _ source2 As IEnumerable(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Union<TSource>( this IQueryable<TSource> source1, IEnumerable<TSource> source2 )
Union 不支援Not supported Function Union(Of TSource) ( _ source1 As IQueryable(Of TSource), _ source2 As IEnumerable(Of TSource), _ comparer As IEqualityComparer(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Union<TSource>( this IQueryable<TSource> source1, IEnumerable<TSource> source2, IEqualityComparer<TSource> comparer )

排序方法Ordering Methods

在 LINQ to Entities 中,大部分的 LINQ 排序方法都受到支援,但會接受 IComparer<T> ,因為比較子無法轉譯成資料來源。Most of the LINQ ordering methods are supported in LINQ to Entities, with the exception of those that accept an IComparer<T>, because the comparer cannot be translated to the data source. 如需詳細資訊,請參閱 LINQ to Entities 查詢中的標準查詢運算子For more information, see Standard Query Operators in LINQ to Entities Queries. 下表所列為支援及不支援的排序方法。The following table lists the supported and unsupported ordering methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
OrderBy 支援Supported Function OrderBy(Of TSource, TKey) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)) _ ) As IOrderedQueryable(Of TSource) IOrderedQueryable<TSource> OrderBy<TSource, TKey>( this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector )
OrderBy 不支援Not supported Function OrderBy(Of TSource, TKey) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ comparer As IComparer(Of TKey) _ ) As IOrderedQueryable(Of TSource) IOrderedQueryable<TSource> OrderBy\<TSource, TKey>( this IQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, IComparer<TKey> comparer )
OrderByDescending 支援Supported Function OrderByDescending(Of TSource, TKey) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)) _ ) As IOrderedQueryable(Of TSource) IOrderedQueryable<TSource> OrderByDescending<TSource, TKey>( this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector )
OrderByDescending 不支援Not supported Function OrderByDescending(Of TSource, TKey) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ comparer As IComparer(Of TKey) _ ) As IOrderedQueryable(Of TSource) IOrderedQueryable<TSource> OrderByDescending\<TSource, TKey>( this IQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, IComparer<TKey> comparer )
ThenBy 支援Supported Function ThenBy(Of TSource, TKey) ( _ source As IOrderedQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)) _ ) As IOrderedQueryable(Of TSource) IOrderedQueryable<TSource> ThenBy<TSource, TKey>( this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector )
ThenBy 不支援Not supported 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) IOrderedQueryable<TSource> ThenBy\<TSource, TKey>( this IOrderedQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, IComparer<TKey> comparer )
ThenByDescending 支援Supported Function ThenByDescending(Of TSource, TKey) ( _ source As IOrderedQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)) _ ) As IOrderedQueryable(Of TSource) IOrderedQueryable<TSource> ThenByDescending<TSource, TKey>( this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector )
ThenByDescending 不支援Not supported Function ThenByDescending(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) IOrderedQueryable<TSource> ThenByDescending\<TSource, TKey>( this IOrderedQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, IComparer<TKey> comparer )
Reverse 不支援Not supported Function Reverse(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As IQueryable(Of TSource) IQueryable<TSource> Reverse<TSource>( this IQueryable<TSource> source )

群組方法Grouping Methods

在 LINQ to Entities 中,大部分的 LINQ 群組方法都受到支援,但會接受 IEqualityComparer<T> ,因為比較子無法轉譯成資料來源。Most of the LINQ grouping methods are supported in LINQ to Entities, with the exception of those that accept an IEqualityComparer<T>, because the comparer cannot be translated to the data source. 如需詳細資訊,請參閱 LINQ to Entities 查詢中的標準查詢運算子For more information, see Standard Query Operators in LINQ to Entities Queries. 下表所列為支援及不支援的群組方法。The following table lists the supported and unsupported grouping methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
GroupBy 支援Supported Function GroupBy(Of TSource, TKey) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)) _ ) As IQueryable(Of IGrouping(Of TKey, TSource)) IQueryable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>( this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector )
GroupBy 不支援Not supported Function GroupBy(Of TSource, TKey) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ comparer As IEqualityComparer(Of TKey) _ ) As IQueryable(Of IGrouping(Of TKey, TSource)) IQueryable<IGrouping\<TKey, TSource>> GroupBy\<TSource, TKey>( this IQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, IEqualityComparer<TKey> comparer )
GroupBy 支援Supported Function GroupBy(Of TSource, TKey, TElement) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ elementSelector As Expression(Of Func(Of TSource, TElement)) _ ) As IQueryable(Of IGrouping(Of TKey, TElement)) IQueryable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>( this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector )
GroupBy 支援Supported Function GroupBy(Of TSource, TKey, TResult) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ resultSelector As Expression(Of Func(Of TKey, IEnumerable(Of TSource), TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> GroupBy\<TSource, TKey, TResult>( this IQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, Expression<Func<TKey, IEnumerable<TSource>, TResult>> resultSelector )
GroupBy 不支援Not supported Function GroupBy(Of TSource, TKey, TElement) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ elementSelector As Expression(Of Func(Of TSource, TElement)), _ comparer As IEqualityComparer(Of TKey) _ ) As IQueryable(Of IGrouping(Of TKey, TElement)) IQueryable<IGrouping\<TKey, TElement>> GroupBy\<TSource, TKey, TElement>( this IQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, Expression<Func\<TSource, TElement>> elementSelector, IEqualityComparer<TKey> comparer
GroupBy 支援Supported Function GroupBy(Of TSource, TKey, TElement, TResult) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ elementSelector As Expression(Of Func(Of TSource, TElement)), _ resultSelector As Expression(Of Func(Of TKey, IEnumerable(Of TElement), TResult)) _ ) As IQueryable(Of TResult) IQueryable<TResult> GroupBy<TSource, TKey, TElement, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, Expression<Func<TKey, IEnumerable<TElement>, TResult>> resultSelector )
GroupBy 不支援Not supported Function GroupBy(Of TSource, TKey, TResult) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ resultSelector As Expression(Of Func(Of TKey, IEnumerable(Of TSource), TResult)), _ comparer As IEqualityComparer(Of TKey) _ ) As IQueryable(Of TResult) IQueryable<TResult> GroupBy\<TSource, TKey, TResult>( this IQueryable<TSource> source, Expression<Func\<TSource, TKey>> keySelector, Expression<Func<TKey, IEnumerable<TSource>, TResult>> resultSelector, IEqualityComparer<TKey> comparer )
GroupBy 不支援Not supported Function GroupBy(Of TSource, TKey, TElement, TResult) ( _ source As IQueryable(Of TSource), _ keySelector As Expression(Of Func(Of TSource, TKey)), _ elementSelector As Expression(Of Func(Of TSource, TElement)), _ resultSelector As Expression(Of Func(Of TKey, IEnumerable(Of TElement), TResult)), _ comparer As IEqualityComparer(Of TKey) _ ) As IQueryable(Of TResult) IQueryable<TResult> GroupBy<TSource, TKey, TElement, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector, Expression<Func<TKey, IEnumerable<TElement>, TResult>> resultSelector, IEqualityComparer<TKey> comparer )

彙總方法Aggregate Methods

LINQ to Entities 中支援大部分接受基本資料類型的匯總方法。Most of the aggregate methods that accept primitive data types are supported in LINQ to Entities. 如需詳細資訊,請參閱 LINQ to Entities 查詢中的標準查詢運算子For more information, see Standard Query Operators in LINQ to Entities Queries. 下表所列為支援及不支援的彙總方法。The following table lists the supported and unsupported aggregate methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
Aggregate 不支援Not supported Function Aggregate(Of TSource) ( _ source As IQueryable(Of TSource), _ func As Expression(Of Func(Of TSource, TSource, TSource)) _ ) As TSource TSource Aggregate<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, TSource, TSource>> func )
Aggregate 不支援Not supported Function Aggregate(Of TSource, TAccumulate) ( _ source As IQueryable(Of TSource), _ seed As TAccumulate, _ func As Expression(Of Func(Of TAccumulate, TSource, TAccumulate)) _ ) As TAccumulate TAccumulate Aggregate<TSource, TAccumulate>( this IQueryable<TSource> source, TAccumulate seed, Expression<Func<TAccumulate, TSource, TAccumulate>> func )
Aggregate 不支援Not supported Function Aggregate(Of TSource, TAccumulate, TResult) ( _ source As IQueryable(Of TSource), _ seed As TAccumulate, _ func As Expression(Of Func(Of TAccumulate, TSource, TAccumulate)), _ selector As Expression(Of Func(Of TAccumulate, TResult)) _ ) As TResult TResult Aggregate<TSource, TAccumulate, TResult>( this IQueryable<TSource> source, TAccumulate seed, Expression<Func<TAccumulate, TSource, TAccumulate>> func, Expression<Func<TAccumulate, TResult>> selector )
Average 支援Supported Function Average ( _ source As IQueryable(Of Decimal) _ ) As Decimal decimal Average( this IQueryable<decimal> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Double) _ ) As Double double Average( this IQueryable<double> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Integer) _ ) As Double double Average( this IQueryable<int> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Long) _ ) As Double double Average( this IQueryable<long> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Nullable(Of Decimal)) _ ) As Nullable(Of Decimal) Nullable<decimal> Average( this IQueryable<Nullable<decimal>> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Nullable(Of Double)) _ ) As Nullable(Of Double) Nullable<double> Average( this IQueryable<Nullable<double>> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Nullable(Of Integer)) _ ) As Nullable(Of Double) Nullable<double> Average( this IQueryable<Nullable<int>> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Nullable(Of Long)) _ ) As Nullable(Of Double) Nullable<double> Average( this IQueryable<Nullable<long>> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Nullable(Of Single)) _ ) As Nullable(Of Single) Nullable<float> Average( this IQueryable<Nullable<float>> source )
Average 支援Supported Function Average ( _ source As IQueryable(Of Single) _ ) As Single float Average( this IQueryable<float> source )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Integer)) _ ) As Double double Average<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, int>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Integer))) _ ) As Nullable(Of Double) Nullable<double> Average<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<int>>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Long)) _ ) As Double double Average<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, long>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Long))) _ ) As Nullable(Of Double) Nullable<double> Average<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<long>>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Single)) _ ) As Single float Average<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, float>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Single))) _ ) As Nullable(Of Single) Nullable<float> Average<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<float>>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Double)) _ ) As Double double Average<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, double>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Double))) _ ) As Nullable(Of Double) Nullable<double> Average<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<double>>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Decimal)) _ ) As Decimal decimal Average<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, decimal>> selector )
Average 不支援Not supported Function Average(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Decimal))) _ ) As Nullable(Of Decimal) Nullable<decimal> Average<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<decimal>>> selector )
Count 支援Supported Function Count(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As Integer int Count<TSource>( this IQueryable<TSource> source )
Count 不支援Not supported Function Count(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As Integer int Count<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
LongCount 支援Supported Function LongCount(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As Long long LongCount<TSource>( this IQueryable<TSource> source )
LongCount 不支援Not supported Function LongCount(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As Long long LongCount<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
Max 支援Supported Function Max(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource Max<TSource>( this IQueryable<TSource> source )
Max 不支援Not supported Function Max(Of TSource, TResult) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, TResult)) _ ) As TResult TResult Max<TSource, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector )
Min 支援Supported Function Min(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource Min<TSource>( this IQueryable<TSource> source )
Min 不支援Not supported Function Min(Of TSource, TResult) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, TResult)) _ ) As TResult TResult Min<TSource, TResult>( this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Decimal) _ ) As Decimal decimal Sum( this IQueryable<decimal> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Double) _ ) As Double double Sum( this IQueryable<double> source
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Integer) _ ) As Integer int Sum( this IQueryable<int> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Long) _ ) As Long long Sum( this IQueryable<long> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Nullable(Of Decimal)) _ ) As Nullable(Of Decimal) Nullable<decimal> Sum( this IQueryable<Nullable<decimal>> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Nullable(Of Double)) _ ) As Nullable(Of Double) Function Sum ( _ source As IQueryable(Of Nullable(Of Double)) _ ) As Nullable(Of Double)Nullable<double> Sum( this IQueryable<Nullable<double>> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Nullable(Of Integer)) _ ) As Nullable(Of Integer) Nullable<int> Sum( this IQueryable<Nullable<int>> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Nullable(Of Long)) _ ) As Nullable(Of Long) Nullable<long> Sum( this IQueryable<Nullable<long>> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Nullable(Of Single)) _ ) As Nullable(Of Single) Nullable<float> Sum( this IQueryable<Nullable<float>> source )
Sum 支援Supported Function Sum ( _ source As IQueryable(Of Single) _ ) As Single float Sum( this IQueryable<float> source )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Integer)) _ ) As Integer int Sum<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, int>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Integer))) _ ) As Nullable(Of Integer) Nullable<int> Sum<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<int>>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Long)) _ ) As Long long Sum<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, long>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Long))) _ ) As Nullable(Of Long) Nullable<long> Sum<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<long>>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Single))) _ ) As Nullable(Of Single) Nullable<float> Sum<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<float>>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Single)) _ ) As Single float Sum<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, float>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Double)) _ ) As Double double Sum<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, double>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Double))) _ ) As Nullable(Of Double) Nullable<double> Sum<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<double>>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Decimal)) _ ) As Decimal decimal Sum<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, decimal>> selector )
Sum 不支援Not supported Function Sum(Of TSource) ( _ source As IQueryable(Of TSource), _ selector As Expression(Of Func(Of TSource, Nullable(Of Decimal))) _ ) As Nullable(Of Decimal) Nullable<decimal> Sum<TSource>( this IQueryable<TSource> source, Expression<Func<TSource, Nullable<decimal>>> selector )

型別方法Type Methods

Entity Framework 中支援處理 CLR 型別轉換和測試的 LINQ 標準查詢運算子。The LINQ standard query operators that deal with CLR type conversion and testing are supported in the Entity Framework. LINQ to Entities 中僅支援對應到概念模型型別的 CLR 型別。Only CLR types that map to conceptual model types are supported in LINQ to Entities. 如需概念模型類型的清單,請參閱 (CSDL) 的概念模型類型 For a list of conceptual model types, see Conceptual Model Types (CSDL). 下表所列為支援及不支援的型別方法。The following table lists the supported and unsupported type methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
Cast 支援 EDM 基本型別Supported for EDM primitive types Function Cast(Of TResult) ( _ source As IQueryable _ ) As IQueryable(Of TResult) IQueryable<TResult> Cast<TResult>( this IQueryable source )
OfType 支援 EntityTypeSupported for EntityType Function OfType(Of TResult) ( _ source As IQueryable _ ) As IQueryable(Of TResult) IQueryable<TResult> OfType<TResult>( this IQueryable source )

分頁方法Paging Methods

LINQ to Entities 的查詢中不支援許多 LINQ 分頁方法。A number of the LINQ paging methods are not supported in LINQ to Entities queries. 如需詳細資訊,請參閱 LINQ to Entities 查詢中的標準查詢運算子For more information, see Standard Query Operators in LINQ to Entities Queries. 下表所列為支援和不支援的分頁方法。The following table lists the supported and unsupported paging methods.

方法Method 支援Support Visual Basic 函式簽章Visual Basic function signature C# 方法簽章C# method signature
ElementAt 不支援Not supported Function ElementAt(Of TSource) ( _ source As IQueryable(Of TSource), _ index As Integer _ ) As TSource TSource ElementAt<TSource>( this IQueryable<TSource> source, int index )
ElementAtOrDefault 不支援Not supported Function ElementAtOrDefault(Of TSource) ( _ source As IQueryable(Of TSource), _ index As Integer _ ) As TSource TSource ElementAtOrDefault<TSource>( this IQueryable<TSource> source, int index )
First 支援Supported Function First(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource First<TSource>( this IQueryable<TSource> source )
First 支援Supported Function First(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As TSource TSource First<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
FirstOrDefault 支援Supported Function FirstOrDefault(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource FirstOrDefault<TSource>( this IQueryable<TSource> source )
FirstOrDefault 支援Supported Function FirstOrDefault(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As TSource TSource FirstOrDefault<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
Last 不支援Not supported Function Last(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource Last<TSource>( this IQueryable<TSource> source )
Last 不支援Not supported Function Last(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As TSource TSource Last<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
LastOrDefault 不支援Not supported Function LastOrDefault(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource LastOrDefault<TSource>( this IQueryable<TSource> source )
LastOrDefault 不支援Not supported Function LastOrDefault(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As TSource TSource LastOrDefault<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
Single 支援Supported Function Single(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource Single<TSource>( this IQueryable<TSource> source )
Single 支援Supported Function Single(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As TSource TSource Single<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
SingleOrDefault 支援Supported Function SingleOrDefault(Of TSource) ( _ source As IQueryable(Of TSource) _ ) As TSource TSource SingleOrDefault<TSource>( this IQueryable<TSource> source )
SingleOrDefault 支援Supported Function SingleOrDefault(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As TSource TSource SingleOrDefault<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
Skip 支援Supported Function Skip(Of TSource) ( _ source As IQueryable(Of TSource), _ count As Integer _ ) As IQueryable(Of TSource) IQueryable<TSource> Skip<TSource>( this IQueryable<TSource> source, int count )
SkipWhile 不支援Not supported Function SkipWhile(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As IQueryable(Of TSource) IQueryable<TSource> SkipWhile<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
SkipWhile 不支援Not supported Function SkipWhile(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Integer, Boolean)) _ ) As IQueryable(Of TSource) IQueryable<TSource> SkipWhile<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, int, bool>> predicate )
Take 支援Supported Function Take(Of TSource) ( _ source As IQueryable(Of TSource), _ count As Integer _ ) As IQueryable(Of TSource) IQueryable<TSource> Take<TSource>( this IQueryable<TSource> source, int count )
TakeWhile 不支援Not supported Function TakeWhile(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Boolean)) _ ) As IQueryable(Of TSource) IQueryable<TSource> TakeWhile<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, bool>> predicate )
TakeWhile 不支援Not supported Function TakeWhile(Of TSource) ( _ source As IQueryable(Of TSource), _ predicate As Expression(Of Func(Of TSource, Integer, Boolean)) _ ) As IQueryable(Of TSource) IQueryable<TSource> TakeWhile<TSource>( this IQueryable<TSource> source, Expression<Func\<TSource, int, bool>> predicate )

另請參閱See also