不能使用类型'System.DateTime的'表达的返回类型'System.Object的“

编程入门 行业动态 更新时间:2024-10-28 04:28:20
本文介绍了不能使用类型'System.DateTime的'表达的返回类型'System.Object的“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经创建了我使用的排序工作正常的表现,直到我打了一个的DateTime 字段,在那里我得到以下错误(在第二线):

I've created an expression that I'm using for sorting which works fine, until I hit a DateTime field, where I get the following error (on the second line):

不能用于返回类型'System.Object的类型的System.DateTime'的表达

Expression of type 'System.DateTime' cannot be used for return type 'System.Object'

下面是我的代码:

ParameterExpression param = Expression.Parameter(typeof(MyEntity), "x"); Expression<Func<MyEntity, object>> sortExpression = Expression.Lambda<Func<AMyEntity, object>>( Expression.Property(param, sortKey), param);

谁能帮助呢?

Can anyone help at all?

推荐答案

就在那里添加一个转换:

Just add a conversion in there:

Expression<Func<MyEntity, object>> sortExpression = Expression.Lambda<Func<AMyEntity, object>>( Expression.Convert( Expression.Property(param, sortKey), typeof(object)), param);

更多推荐

不能使用类型'System.DateTime的'表达的返回类型'System.Object的“

本文发布于:2023-05-31 12:01:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/391363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   System   DateTime   Object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!