1.Expression
expression<func<double, double>> exp = a = Math.sin (a);
The delegate type func<double, Double>, which qualifies the resulting expression tree to be a unary lambda function that accepts a double and returns a double
<func<double, double, double, double, double> the input parameter is 4 double, which returns a double type
static void Main (string[] args) { expression< func< Console.WriteLine (Calc. Calculate (1, 2, 3, 4)); }
2. Use in LINQ to SQL
LoadWith method, input type is generic T, input parameter is expression, return System.Linq.Expressions.LambdaExpression
Loadswith method, accept lambdaexpression[], load data
<func<t, object> input generic, returns object (because the return type is undefined, so it is an object)
public partial class Db//for db.dbml filespartial class
{
public static LambdaExpression loadwith<t> (expression<func<t, object>> Expression)
{
return expression;
}
public void Loadswith (params lambdaexpression[] expressions)
{
var dlo = new DataLoadOptions ();
foreach (var expression in expressions)
{
Dlo. LoadWith (expression);
}
Loadoptions = Dlo;
}
public static Db Open (bool readOnly = False) {
var db = new db ();
if (readOnly) db. objecttrackingenabled = false;
return DB;
}
}
LoadWith is interpreted on MSDN by using a lambda expression to retrieve the specified data related to the primary target. LoadWith can load data from related tables with an SQL statement
For example student table inner JOIN class table, this is the meaning of loadwith.
Call:
using (var db = Db.open ()) { db. Loadswith ( db.loadwith<Project> (p = p.client), db.loadwith<Project> (p = p.files) ); var project = db. Projects.singleordefault (p = = P.id = = form. ID);}
exploring Lambda Expression in C #
Expression Tree Getting Started Guide
Https://msdn.microsoft.com/en-us/library/bb397687.aspx
use expression expressions to resolve queries similar to select in SQL (for Small to medium projects)
LINQ to SQL
。
Lambda Expression in C #