[英]Expression of type 'System.Int16' cannot be used for return type 'System.Object'
public IQueryable<Users> SelectAdmin<TProp>(string sSortExpression, string sSortOrder ,long[] IAds, int iStart, int iEnd, long iId)
{
var param = Expression.Parameter(typeof(Users));
var propExpression = Expression.Lambda<Func<Users, TProp>>(Expression.Property(param, sSortExpression), param);
if (sSortOrder == "asc")
{
return objCouponUow.Repository<Users>().Entities.Where(x => x.UserGroup == 9 && x.Validate == 0 && x.Deleted == false && IAds.Contains(x.UserParent)).OrderBy(propExpression).Skip(iStart).Take(iEnd - iStart);
}
}
this is my function .. i Am getting the error in line : 这是我的功能..我收到了错误:
var propExpression = Expression.Lambda<Func<Users, TProp>>(Expression.Property(param, sSortExpression), param);
When the 'sSortExpression' which is a column in Users Table is of Type Varchar , No Problem But If its Int type.. Error Occurs Expression of type 'System.Int16' cannot be used for return type 'System.Object' 当用户表中的列'sSortExpression'是Type Varchar时,没有问题但是如果它的Int类型..错误发生'System.Int16'类型的表达式不能用于返回类型'System.Object'
How can i Correct this problem? 我怎样才能解决这个问题?
有可能你没有给那里分配一个对象(sSortExpression),因为你说它是一个列,也许你将项目对象集合指定为int,所以得到了错误。
The problem here is that <Tprop>
is not of the Type Int16
and the string you are passing which is a columnname of the type Int16
这里的问题是<Tprop>
不是Int16
类型和您传递的字符串,它是Int16
类型的列名
You can simply specify the <Tprop>
wherever you are calling the function SelectAdmin<TProp>
. 你可以简单地指定<Tprop>
无论你调用的函数SelectAdmin<TProp>
for example: 例如:
`SelectAdmin<int>(.......your parameters here);`
if the sSortExpression is of the Type int16. 如果sSortExpression属于Type int16。 If it is of the type DateTime
you can call like this 如果它是DateTime
类型,你可以像这样调用
SelectAdmin<DateTime>(.......your parameters here);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.