Sequence Operators

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>.

Examples of Unsupported
System.Linq.Enumerable.Where<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)
System.Linq.Enumerable.Select<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)
System.Linq.Enumerable.Select<TSource,TResult>(IEnumerable<TSource>, Func<TSource,TResult>)
System.Linq.Enumerable.TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)
System.Linq.Enumerable.TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)
System.Linq.Enumerable.SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Boolean>)
System.Linq.Enumerable.SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource,Int32,Boolean>)
System.Linq.Enumerable.GroupBy<TSource,TKey,TElement>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)
System.Linq.Enumerable.GroupBy<TSource,TKey,TElement,TResult>(IEnumerable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, Func<TKey,IEnumerable<TElement>,TResult>, IEqualityComparer<TKey>)
System.Linq.Enumerable.Reverse<TSource>(IEnumerable<TSource>)
System.Linq.Enumerable.DefaultIfEmpty<TSource>(IEnumerable<TSource>, TSource)
System.Linq.Enumerable.ElementAt<TSource>(IEnumerable<TSource>, Int32)
System.Linq.Enumerable.ElementAtOrDefault<TSource>(IEnumerable<TSource>, Int32)
System.Linq.Enumerable.Range(Int32, Int32)
System.Linq.Enumerable.Repeat<TResult>(TResult, Int32)
System.Linq.Enumerable.Empty<TResult>()
System.Linq.Enumerable.Contains<TSource>(IEnumerable<TSource>, TSource)
System.Linq.Enumerable.Aggregate<TSource>(IEnumerable<TSource>, Func<TSource,TSource,TSource>)
System.Linq.Enumerable.Aggregate<TSource,TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>)
System.Linq.Enumerable.Aggregate<TSource,TAccumulate,TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, Func<TAccumulate,TResult>)
System.Linq.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

Data Types and Functions