我已经创建了一个用于排序的表达式,可以正常工作,直到我找到DateTime
字段,我得到以下错误(在第二行):类型的System.DateTime“的'System.DateTime'类型的表达式不能用于返回类型'System.Object'
表达式不能用于返回类型 'System.Object的'
这里是我的代码:
ParameterExpression param = Expression.Parameter(typeof(MyEntity), "x");
Expression<Func<MyEntity, object>> sortExpression =
Expression.Lambda<Func<AMyEntity, object>>(
Expression.Property(param, sortKey), param);
任何人都可以帮忙吗?
的可能重复['System.Int32'类型的表达式不能用于返回类型'System.Object'](http://stackoverflow.com/questions/2200209/expression-of-type-system-int32-cannot-be-used- for-return-type-system-object) – nawfal