分类:
EF
表达式树(关键字Expression<Func<对象, 数据类型>>)可以动态的拼接lamdba表达式
- //对象部分
-
- public class TableInfo
- {
- public int Sid { get; set; }
- public string UserName { get; set; }
- public int? Sum { get; set; }
- public int? Max { get; set; }
- public int? Min { get; set; }
- public double Avg { get; set; }
- public string Father { get; set; }
- public string Mather { get; set; }
- }
构建 lamdba
- var left = Expression.Parameter(typeof(TableInfo), "a");
-
- var body = Expression.Property(left, "Max");
-
- //Func<类名, 参数类型>
- Expression<Func<TableInfo, int?>> lamdba = Expression.Lambda<Func<TableInfo, int?>>(body, left);
-
- //生成的lamdba 表达式{ a => a.Max }
评价