Labels

Wednesday, July 22, 2009

LINQ to SQL - Operators

Hi,

 

There are two type of Operators.

 

-          Deferred

-          Non-Deferred

 

 

 

string[] presidents = {

"Adams", "Arthur", "Buchanan", "Bush", "Carter", "Cleveland",

"Clinton", "Coolidge", "Eisenhower", "Fillmore", "Ford", "Garfield",

"Grant", "Harding", "Harrison", "Hayes", "Hoover", "Jackson",

"Jefferson", "Johnson", "Kennedy", "Lincoln", "Madison", "McKinley",

"Monroe", "Nixon", "Pierce", "Polk", "Reagan", "Roosevelt", "Taft",

"Taylor", "Truman", "Tyler", "Van Buren", "Washington", "Wilson"};

 

 

 

Deferred Operators

 

Restriction           

Where

 

public static IEnumerable<T> Where<T>(this IEnumerable<T> source,Func<T, bool> predicate);

public static IEnumerable<T> Where<T>(this IEnumerable<T> source,Func<T, int, bool> predicate);

 

Projection           

Select

SelectMany

 

public static IEnumerable<S> Select<T, S>(this IEnumerable<T> source,Func<T, S> selector);

public static IEnumerable<S> Select<T, S>(this IEnumerable<T> source,Func<T, int, S> selector);

 

public static IEnumerable<S> SelectMany<T, S>(this IEnumerable<T> source,Func<T, IEnumerable<S>> selector);

public static IEnumerable<S> SelectMany<T, S>(this IEnumerable<T> source,Func<T, int, IEnumerable<S>> selector);.

 

Partitioning           

Skip

SkipWhile

Take

TakeWhile

 

public static IEnumerable<T> Skip<T>(this IEnumerable<T> source,int count);

public static IEnumerable<T> SkipWhile<T>(this IEnumerable<T> source,Func<T, bool> predicate);

public static IEnumerable<T> SkipWhile<T>(this IEnumerable<T> source,Func<T, int, bool> predicate);

 

 

Concatenation           

Concat

 

public static IEnumerable<T> Concat<T>(this IEnumerable<T> first,IEnumerable<T> second);

Ordering           

OrderBy

OrderByDescending

Reverse

ThenBy

ThenByDescending

 

 

Join                 

Join

GroupJoin

 

public static IEnumerable<V> Join<T, U, K, V>(this IEnumerable<T> outer,IEnumerable<U> inner,Func<T, K> outerKeySelector,Func<U, K> innerKeySelector, Func<T, U, V> resultSelector);

 

public static IEnumerable<V> GroupJoin<T, U, K, V>(this IEnumerable<T> outer,IEnumerable<U> inner,Func<T, K> outerKeySelector,Func<U, K> innerKeySelector,Func<T, IEnumerable<U>, V> resultSelector);

 

Grouping           

GroupBy

 

 

Set                  

Distinct

Except

Intersect

Union

 

public static IEnumerable<T> Distinct<T>(this IEnumerable<T> source);

public static IEnumerable<T> Union<T>(this IEnumerable<T> first,IEnumerable<T> second);

public static IEnumerable<T> Intersect<T>(this IEnumerable<T> first,IEnumerable<T> second);

public static IEnumerable<T> Except<T>(this IEnumerable<T> first,IEnumerable<T> second);

Conversion           

Cast

OfType

 

public static IEnumerable<T> Cast<T>(this IEnumerable source);

public static IEnumerable<T> OfType<T>(this IEnumerable source);

public static IEnumerable<T> AsEnumerable<T>(this IEnumerable<T> source);

Element                       

DefaultIfEmpty

ElementAt

ElementAtOrDefault

First

FirstOrDefault

Last

LastOrDefault

Single

SingleOrDefault

 

 

public static T First<T>(this IEnumerable<T> source);

public static T First<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T FirstOrDefault<T>(this IEnumerable<T> source);

public static T FirstOrDefault<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T Last<T>(this IEnumerable<T> source);

public static T Last<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T LastOrDefault<T>(this IEnumerable<T> source);

public static T LastOrDefault<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T Single<T>(this IEnumerable<T> source);

public static T Single<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T SingleOrDefault<T>(this IEnumerable<T> source);

public static T SingleOrDefault<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T ElementAt<T>(this IEnumerable<T> source,int index);

public static T ElementAtOrDefault<T>(this IEnumerable<T> source,int index);

 

Generation

Empty

Range

Repeat

 

public static IEnumerable<T> Empty<T>();

public static IEnumerable<int> Range(int start,int count);

public static IEnumerable<T> Repeat<T>(T element,int count);

 

 

 

Non Deferred Operators

 

Conversion

ToArray

ToDictionary

ToList

ToLookup

 

public static T[] ToArray<T>(this IEnumerable<T> source);

public static List<T> ToList<T>(this IEnumerable<T> source);

 

public static Dictionary<K, T> ToDictionary<T, K>(this IEnumerable<T> source,Func<T, K> keySelector);

public static Dictionary<K, T> ToDictionary<T, K>(this IEnumerable<T> source,Func<T, K> keySelector,IEqualityComparer<K> comparer);

 

public static Dictionary<K, E> ToDictionary<T, K, E>(this IEnumerable<T> source,Func<T, K> keySelector,Func<T, E> elementSelector);

public static Dictionary<K, E> ToDictionary<T, K, E>(this IEnumerable<T> source,Func<T, K> keySelector,Func<T, E> elementSelector,IEqualityComparer<K> comparer);

 

public static ILookup<K, T> ToLookup<T, K>(this IEnumerable<T> source,Func<T, K> keySelector);

public static ILookup<K, T> ToLookup<T, K>(this IEnumerable<T> source,Func<T, K> keySelector,IEqualityComparer<K> comparer);

public static ILookup<K, E> ToLookup<T, K, E>(this IEnumerable<T> source,Func<T, K> keySelector,Func<T, E> elementSelector);

public static ILookup<K, E> ToLookup<T, K, E>(this IEnumerable<T> source,Func<T, K> keySelector,Func<T, E> elementSelector,IEqualityComparer<K> comparer);

 

 

Equality

SequenceEqual

 

public static bool SequenceEqual<T>(this IEnumerable<T> first,IEnumerable<T> second);

public static bool SequenceEqual<T>(this IEnumerable<T> first,IEnumerable<T> second,IEqualityComparer<T> comparer);

 

Element

First

FirstOrDefault

Last

LastOrDefault

Single

SingleOrDefault

ElementAt

ElementAtOrDefault

 

public static T First<T>(this IEnumerable<T> source);

public static T First<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T FirstOrDefault<T>(this IEnumerable<T> source);

public static T FirstOrDefault<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T Last<T>(this IEnumerable<T> source);

public static T Last<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T LastOrDefault<T>(this IEnumerable<T> source);

public static T LastOrDefault<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T Single<T>(this IEnumerable<T> source);

public static T Single<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T SingleOrDefault<T>(this IEnumerable<T> source);

public static T SingleOrDefault<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static T ElementAt<T>(this IEnumerable<T> source,int index);

public static T ElementAtOrDefault<T>(this IEnumerable<T> source,int index);

 

Quantifiers

Any

All

Contains

 

public static bool Any<T>(this IEnumerable<T> source);

public static bool Any<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static bool All<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static bool Contains<T>(this IEnumerable<T> source,T value);

public static bool Contains<T>(this IEnumerable<T> source,T value,IEqualityComparer<T> comparer);

 

Aggregate

Count

LongCount

Sum

Min

Max

Average

Aggregate

 

public static int Count<T>(this IEnumerable<T> source);

public static int Count<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static long LongCount<T>(this IEnumerable<T> source);

public static long LongCount<T>(this IEnumerable<T> source,Func<T, bool> predicate);

 

public static Numeric Sum(this IEnumerable<Numeric> source);

public static Numeric Sum<T>(this IEnumerable<T> source,Func<T, Numeric> selector);

 

public static Numeric Min(this IEnumerable<Numeric> source);

public static T Min<T>(this IEnumerable<T> source);

public static Numeric Min<T>(this IEnumerable<T> source,Func<T, Numeric> selector);

public static S Min<T, S>(this IEnumerable<T> source,Func<T, S> selector);

 

public static Numeric Max(this IEnumerable<Numeric> source);

public static T Max<T>(this IEnumerable<T> source);

public static Numeric Max<T>(this IEnumerable<T> source,Func<T, Numeric> selector);

public static S Max<T, S>(this IEnumerable<T> source,Func<T, S> selector);

 

public static Result Average(this IEnumerable<Numeric> source);

public static Result Average<T>(this IEnumerable<T> source,Func<T, Numeric> selector);

 

public static T Aggregate<T>(this IEnumerable<T> source,Func<T, T, T> func);

public static U Aggregate<T, U>(this IEnumerable<T> source,U seed,Func<U, T, U> func);

 

 

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

No comments:

Post a Comment