LINQ体验(17)——LINQ to SQL语句之动态查询
example:


using (EmployeeDBDataContext db = new EmployeeDBDataContext())
{
var l = db.VW_EMPLOYEEs;
ParameterExpression param = Expression.Parameter( typeof (VW_EMPLOYEE), " p " );
Expression left = Expression.Property(param, typeof (VW_EMPLOYEE).GetProperty( " EMPLID " ));
Expression right = Expression.Constant(emp.EMPLID);
Expression filter = Expression.Equal(left, right);
Expression pred = Expression.Lambda(filter, param);
Expression expr = Expression.Call( typeof (Queryable), " Where " ,
new Type[] { typeof (VW_EMPLOYEE) },
Expression.Constant(l), pred);
IQueryable < VW_EMPLOYEE > query = db.VW_EMPLOYEEs.AsQueryable().Provider.CreateQuery < VW_EMPLOYEE > (expr);
return query.ToList();
}
{
var l = db.VW_EMPLOYEEs;
ParameterExpression param = Expression.Parameter( typeof (VW_EMPLOYEE), " p " );
Expression left = Expression.Property(param, typeof (VW_EMPLOYEE).GetProperty( " EMPLID " ));
Expression right = Expression.Constant(emp.EMPLID);
Expression filter = Expression.Equal(left, right);
Expression pred = Expression.Lambda(filter, param);
Expression expr = Expression.Call( typeof (Queryable), " Where " ,
new Type[] { typeof (VW_EMPLOYEE) },
Expression.Constant(l), pred);
IQueryable < VW_EMPLOYEE > query = db.VW_EMPLOYEEs.AsQueryable().Provider.CreateQuery < VW_EMPLOYEE > (expr);
return query.ToList();
}
Lambda :
http://www.cnblogs.com/killuakun/archive/2008/08/03/1259389.html
http://www.cnblogs.com/terrylee/archive/2008/08/01/custom-linq-provider-part-1-expression-tree.html
http://www.cnblogs.com/ninputer/archive/2009/08/28/expression_tree1.html
http://www.cnblogs.com/126/archive/2007/08/15/857193.html
http://www.cnblogs.com/lyj/archive/2008/03/25/1122157.html
Lambda Expression Tree:
打造自己的LINQ Provider(上):Expression Tree揭秘
打造自己的LINQ Provider(中):IQueryable和IQueryProvider
Linq To Sql进阶系列(六)用object的动态查询与保存log篇
Expression Tree上手指南 (一) ==>
NHB
http://www.kontac.net/site/
http://www.cnblogs.com/lyj/archive/2008/11/10/1330542.html