none
定义泛型方法 RRS feed

  • 问题

  • 我在Linq使用分页存储过程,这个存储过程可以传入不同的表名作参数。
    所以我想在Linq中创建一个泛型方法,节省代码,不必为每个表都创建一个存储过程的方法,以下,是我创建的方法:
            [Function(Name = "[dbo].[SP_PageView]")]
            public ISingleResult<TEntity> ProcedurePageView<TEntity>(
                [Parameter(Name = "@TableName", DbType = "sysname")] string tableName,
                [Parameter(Name = "@KeyFields", DbType = "nvarchar(1000)")] string keyFields,
                [Parameter(Name = "@PageNumber", DbType = "int")] int? pageNumber,
                [Parameter(Name = "@PageSize", DbType = "int")] int? pageSize,
                [Parameter(Name = "@ShowFields", DbType = "nvarchar(1000)")] string showFields,
                [Parameter(Name = "@OrderFields", DbType = "nvarchar(1000)")] string orderFields,
                [Parameter(Name = "@WhereCondition", DbType = "nvarchar(1000)")] string whereCondition,
                [Parameter(Name = "@PageCount", DbType = "int")] ref int? pageCount
                ) where TEntity : class
            {
                IExecuteResult result = this.ExecuteMethodCall(
                    this,
                    ((MethodInfo)MethodInfo.GetCurrentMethod()),
                    tableName,
                    keyFields,
                    pageNumber,
                    pageSize,
                    showFields,
                    orderFields,
                    whereCondition,
                    pageCount);
                pageCount = ((System.Nullable<int>)(result.GetParameterValue(7)));
                return ((ISingleResult<TEntity>)(result.ReturnValue));
            }
    编译没有问题,运行报错:
    “方法 System.Data.Linq.ISingleResult`1[TEntity] sp_PageView[TEntity](System.String, System.String, System.Nullable`1[System.Int32], System.Nullable`1

    [System.Int32], System.String, System.String, System.String, System.Nullable`1[System.Int32] ByRef) 是泛型方法定义。”

    错误指向方法中的第一条语句。
    请问哪里的问题啊?


    做最好的自己
    2009年7月15日 1:08

答案

全部回复