LinqToSQL3

Lambda

Lambda expressions and anonymous method is very similar, but more flexible than Lambda expressions of anonymous methods, and the syntax is more concise than the anonymous method.

You can create delegate use Lambda expressions in LINQ, the delegate will be called upon to execute the query later.

Lambda expressions using the operator "=>." This operator means "flows", any input parameters for the left, right side of the expression can, can also block.

Lambda may include any number of statements, but it will usually kept two or three statements, primarily for ease of reading and to prevent it too complicated.

Use Lambda expressions to remember the following rules:

Lambda expression 1. If a return value, the return value must be converted implicitly to a delegate type.

The number of parameters 2.Lambda expression must contain the same number of arguments with the delegate type.

3. Each input parameter must implicitly trust the corresponding conversion parameters.

var pro=context.products.Single(p=>p.id==id);

This query can also be written as:

var pro=from c in context where c.id==id select c;

Both queries return the same output structure, but Lambda expressions use the syntax within the connection becomes a way to write the query expression.

Single standard query operators to return a single element in the sequence. P is a left operator input variables corresponding to the query expression p

 

Guess you like

Origin www.cnblogs.com/jxl123456/p/11109682.html
3