Sequence Operators (LINQ to SQL)
W tym artykule
Generally speaking, LINQ to SQL does not support sequence operators that have one or more of the following qualities:
Take a lambda with an index parameter.
Rely on the properties of sequential rows, such as TakeWhile .
Rely on an arbitrary CLR implementation, such as IComparer<T> .
Enumerable.Where<TSource>(IEnumerable<TSource>, Func<TSource, Int32, Boolean>)
Enumerable.Select<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>)
Enumerable.Select<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>)
Enumerable.TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)
Enumerable.TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource, Int32, Boolean>)
Enumerable.SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)
Enumerable.SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource, Int32, Boolean>)
Enumerable.GroupBy<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>)
Enumerable.GroupBy<TSource, TKey, TElement, TResult>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, Func<TKey, IEnumerable<TElement>, TResult>, IEqualityComparer<TKey>)
Enumerable.Reverse<TSource>(IEnumerable<TSource>)
Enumerable.DefaultIfEmpty<TSource>(IEnumerable<TSource>, TSource)
Enumerable.ElementAt<TSource>(IEnumerable<TSource>, Int32)
Enumerable.ElementAtOrDefault<TSource>(IEnumerable<TSource>, Int32)
Enumerable.Range(Int32, Int32)
Enumerable.Repeat<TResult>(TResult, Int32)
Enumerable.Empty<TResult>()
Enumerable.Contains<TSource>(IEnumerable<TSource>, TSource)
Enumerable.Aggregate<TSource>(IEnumerable<TSource>, Func<TSource, TSource, TSource>)
Enumerable.Aggregate<TSource, TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>)
Enumerable.Aggregate<TSource, TAccumulate, TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>)
Enumerable.SequenceEqual
Differences from .NET
All supported sequence operators work as expected in the common language runtime (CLR) except for Average. Average returns a value of the same type as the type being averaged, whereas in the CLR Average always returns either a Double or a Decimal . If the source argument is explicitly cast to double / decimal or the selector casts to double / decimal, the resulting SQL will also have such a conversion and the result will be as expected.
See Also
Other Resources
Data Types and Functions (LINQ to SQL)