http://marisolca.blogspot.com/2015/07/linq.html
http://marisolca.blogspot.com/2015/10/linq-v-example-of-queries.html
Type Parameters:
TSource: The type of the elements of source.
TResult: The type of the value returned by selector.
Parameters:
source: A sequence of values to invoke a transform function on.
selector: A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
Returns:
An System.Collections.Generic.IEnumerable<T> whose elements are the result of invoking the transform function on each element of source.
LINQ pattern operators
For this example we will use these classes
Data
Where():Filter the original sequence in base on predicate logic.Return an IEnumerable(sequence).If any argument is null , ArgumentNullException exception launches.
The method has two method overloading
For Example:
select()/selectMany():Projection of original sequence in other base on one tranformation function
Method overloading
For example:
Unlike Select () standard query operator SelectMany () is normally used in consultations with nested generators, and aims to make a projection of one to many:
Method overloading
Note that it was necessary to assign explicit names to properties resulting anonymous type, because otherwise it would be with two properties called Name, which is obviously unacceptable.
OrderBy/ThenBy(): Sort ascending of the original sequence base on calculation functions of the sort key.
OrderBYDescending()/thenByDescending(): Sort descending of the original sequence base to calculation functions of the sort key
Method overloading
GroupBy():Create groups from original sequence base on calculation function the grouping key
Method overloading
public static IEnumerable<IGrouping<TKey, TSource>>GroupBy<TSource, TKey>(this IEnumerable<TSource> source,Func<TSource, TKey> keySelector);
public static IEnumerable<IGrouping<TKey, TSource>>GroupBy<TSource, TKey>(this IEnumerable<TSource> source,Func<TSource, TKey> keySelector,IEqualityComparer<TKey> comparer);
public static IEnumerable<IGrouping<TKey, TElement>>GroupBy<TSource, TKey, TElement>(
this IEnumerable<TSource> source,Func<TSource, TKey> keySelector,Func<TSource, TElement> elementSelector);
public static IEnumerable<IGrouping<TKey, TElement>>GroupBy<TSource, TKey, TElement>(
this IEnumerable<TSource> source,Func<TSource, TKey> keySelector,Func<TSource, TElement> elementSelector,IEqualityComparer<TKey> comparer);
IGrouping<TKey,TElement> return any of above four operators
public interface IGrouping<TKey,TElement>;IEnumerable<TElement>
{
TKey key{get;}
}
KeySelector parameters represent a function that calculates, each element sequence input, the grouping key value that determine to which group belongs the element
elementSelector represent a function of mapping that determine what object is associated to a group.
Method overloading
public static IEnumerable<TResult>Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer,IEnumerable<TInner> inner,Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,Func<TOuter, TInner, TResult> resultSelector);
public static IEnumerable<TResult>Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer,IEnumerable<TInner> inner,Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,Func<TOuter, TInner, TResult> resultSelector,
IEqualityComparer<TKey> comparer);
the arguments outerKeySelector e innerKeySelector are functions that extracting the values of the key meeting to each of the elements the input sequence (outer) and the second sequence (inner), respectively.
resultSelector is the function responsible for generating elements of result sequence from each pair of elements of the sequence whose values match
No special query operators to deploy meetings outside the left or right, but these can be implemented easily by GroupJoin () operator discussed below.
GroupJoin():
grouping meeting of original sequence and second sequence base on calculation functions of the key meeting for each of the sequence
resultSelector is the function responsible for generating elements of result sequence from each pair of elements of the sequence whose values match.
Method overloading
public static IEnumerable<TResult>GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer,IEnumerable<TInner> inner,Func<TOuter, TKey> outerKeySelector,Func<TInner, TKey> innerKeySelector,Func<TOuter, IEnumerable<TInner>, TResult> resultSelector);
public static IEnumerable<TResult>GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer,IEnumerable<TInner> inner,Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,Func<TOuter, IEnumerable<TInner>, TResult> resultSelector,IEqualityComparer<TKey> comparer);
the arguments outerKeySelector e innerKeySelector are functions that extracting the values of the key meeting to each of the elements the input sequence (outer) and the second sequence (inner), respectively.




























No hay comentarios:
Publicar un comentario