blogs

miércoles, 23 de septiembre de 2015

Linq III

Deferred execution 
In previous post http://marisolca.blogspot.com/2015/09/linq.html we made queries that do not get really until produce the iteration on it,it is a default behavior of LINQ, but if we want to "cache" in memory   the result of the query to reuse.We will use  the standard operators as ToArray<T>(),ToList<T>(),ToDictionary<T,K>() and ToLookup<T,K,E>()
For Example,we want to get the name of employees that start with letter "A"

Our class Employee




Our method gets a list of employees


Create a test method to see the result of deferred execution 



Using the standard operators


The result of the execution





Syntax the query expressions

<Expression query>::=<FROM clause><body clause>
<FROM clause>::=FROM<element> IN<origin expression>

<body clause>::=<body clause query>*
                            <end clause query>
                            <continuation > ?

<body clause query>::= (<FROM clause>
                                     | <JOIN clause>
                                      | <JOIN-INTO clause>
                                    | <LET clause>
                                    | <WHERE clause>
                                     |<ORDERBY clause>)

<LET clause>::=LET<element>=<Expresion.selection>

<WHERE clause> ::=WHERE<expression.filter>

<JOIN clause>::=JOIN<element> IN <expresion.origin>
                        ON<Expression.key> EQUALS<expression.key>

<JOIN-INTO clause>::= JOIN<element> IN <expression.origin>
                                   ON<expression.key> EQUALS<expression.key>
                                   INTO<element>

<ORDERBY clause>::= ORDERBY<ordinations>

<ordinations>::=<ordination>| <ordinations>,<ordination>
<ordination>:=<expression.key>(ascending | descending)?

<end clause query>::=(<SELECT clause> |  <GROUPBY clause>

<SELECT clause>::=SELECT<expression.selection>
<GROUPBY clause>::=GROUP<expression.selection> BY<expression.key>

<continuation>::INTO<element><body query>

Meta-language :
* - zero or more times
(.... | ....) - alternative
? - optional element

In the following post, we will do examples the queries


No hay comentarios:

Publicar un comentario