【发布时间】:2014-10-14 15:39:36
【问题描述】:
目前我正在使用表达式生成器来生成动态查询。
我为 int、日期时间和字符串运算符创建了动态表达式。现在我被困在某一点上。
我想通过表达式比较日期时间的月份部分。
我们正在传递日期时间的属性,并希望为该属性的月份创建表达式。
代码:
public static Expression GetDynamicquery<TSource>(
string property, object value, ParameterExpression p)
{
var propertyReference = Expression.Property(p, property);
var constantReference = Expression.Constant(value);
var expression = Expression.Equal(propertyReference, constantReference);
MethodInfo method = null;
return Expression.LessThanOrEqual(propertyReference, constantReference);
}
这里的属性是我传递给 Tsource 的属性的名称。
p是Tsource类型的参数表达式。
我想要这个月所有生日的结果。
【问题讨论】:
-
你的代码现在做什么?
-
@user1522548 这是部分代码,但想法是使用操作符枚举和所有 dayatype 创建动态 linq 查询。我想访问 datetime 数据类型的 year 属性。
标签: linq entity-framework expression-trees dynamic-linq