简体   繁体   English

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

[英]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.

相关问题 类型'System.Int32'的表达式不能用于返回类型'System.Object' - Expression of type 'System.Int32' cannot be used for return type 'System.Object' “System.Int64”类型的表达式不能用于返回类型“System.Object” - Expression of type 'System.Int64' cannot be used for return type 'System.Object' 可查询 <T> 。订购 <T, object> 抛出:无法将类型“ System.Int16”强制转换为类型“ System.Object” - IQueryable<T>.OrderBy<T, object> throws: Unable to cast the type 'System.Int16' to type 'System.Object' 类型&#39;System.Int16&#39;的对象不能转换为类型&#39;System.Nullable`1 [System.Int32] - Object of type 'System.Int16' cannot be converted to type 'System.Nullable`1[System.Int32] C#无法将类型为&#39;system.int16 [*]&#39;的对象转换为类型为&#39;system.Int16 []&#39;的对象 - c# unable to cast object of type 'system.int16[*]' to type 'system.Int16[]' 类型'System.Int32'的表达式不能用于方法'Boolean Equals(System.Object)'的'System.Object'类型的参数 - Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' of method 'Boolean Equals(System.Object)' 类型&#39;System.Int32&#39;的表达式不能用于方法&#39;Boolean Equals(System.Object)&#39;的类型&#39;System.Object&#39;的参数 - Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' of method 'Boolean Equals(System.Object)' Linq和Equality Operator:类型'System.Int32'的表达式不能用于'System.Object'类型的参数 - Linq and the Equality Operator: Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' &#39;System.DateTime&#39;类型的表达式不能用于返回类型&#39;System.Object&#39; - Expression of type 'System.DateTime' cannot be used for return type 'System.Object' Autofac.Core.DependencyResolutionException:类型“”的表达式不能用于 Autofac 6.2 中的返回类型“System.Object” - Autofac.Core.DependencyResolutionException: Expression of type '' cannot be used for return type 'System.Object' in Autofac 6.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM