Linq动态查询--Expression.LessThan问题
cabps 2009-08-24 10:38:03 right = Expression.Constant(Convert.ToDateTime(outTime));
right = Expression.Convert(right, typeof(DateTime));
left = Expression.Property(param, typeof(Table1).GetProperty("OutOfTime"));
filter = Expression.LessThan(left, right);
其中OutOfTime字段在Table1表中为DateTime类型并且为可空,这时问题来了。
Expression.LessThan拼接filter时说"The binary operator Equal is not defined for the types 'System.Nullable`1[System.DateTime]' and 'System.DateTime'."
自己搜了半天,搜到的结果都说这个错误是由于Expression的两边都必须为同一类型导致(the expression tree needs both sides of the expression to be the same type)。不太明白,OutOfTime此时明明不为空,为什么不能比较?
不光LessThan,LessThanOrEqual、GreaterThan、GreaterThanOrEqual也存在相同问题。
如何解决?请各位高人不吝赐教,谢谢。