0

我有以下代码,我可以弄清楚为什么它的参数无效:

 AuditDAL ad = new AuditDAL();
 var agencies = ad.SearchAgencies("Ak001", "");

string col = param.sColumns.Split(',')[param.iSortCol_0];
string orderby = col + " " + param.sSortDir_0;

// 'AMS.Helper.PaginatedList.PaginatedList(System.Linq.IQueryable, int, int)' 的最佳重载方法匹配有一些无效参数 C:\NexGen\AMS\DEV\Source\AMS\Controllers\AuditController.cs

var qry = new PaginatedList<AuditAgency>(agencies, param.iDisplayStart, param.iDisplayLength);

分页列表代码:

namespace AMS.Helper
{
    public class PaginatedList<T> : List<T> {

        public int PageIndex  { get; private set; }
        public int PageSize   { get; private set; }
        public int TotalCount { get; private set; }
        public int TotalPages { get; private set; }

        public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize) {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = source.Count();
            TotalPages = (int) Math.Ceiling(TotalCount / (double)PageSize);

            this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
        }

        public bool HasPreviousPage {
            get {
                return (PageIndex > 0);
            }
        }

        public bool HasNextPage {
            get {
                return (PageIndex+1 < TotalPages);
            }
        }
    }
}

搜索机构代码:

public IEnumerable<AuditAgency> SearchAgencies(string ori, string name)
        {
            List<AuditAgency> agencies = new List<AuditAgency>();
            using (var conn = new SqlConnection(_connectionString))
            {
                var com = new SqlCommand();
                com.Connection = conn;
                com.CommandType = CommandType.StoredProcedure;
                string term = "Ori";

                if (!String.IsNullOrEmpty(ori))
                {
                    term = "Ori";
                    com.Parameters.Add(new SqlParameter
                    {
                        ParameterName = "@ORI",
                        Value = ori
                    });
                }
                if (!String.IsNullOrEmpty(name))
                {
                    term = "legal_name";
                    com.Parameters.Add(new SqlParameter
                    {
                        ParameterName = "@Name",
                        Value = name
                    });
                }
                com.CommandText = "Audit_Get_Agency_List";
                var adapt = new SqlDataAdapter();
                adapt.SelectCommand = com;
                var dataset = new DataSet();
                adapt.Fill(dataset);

                agencies = (from c in dataset.Tables[0].AsEnumerable()
                            select new AuditAgency()
                            {
                                Agency_ID = Convert.ToInt32(c["Agency_Id"]),
                                Agency_Name = c["Agency_Name"].ToString(),
                                Agency_Ori = c["ORI"].ToString(),
                                COPSAuditNumber = c["COPSAuditNumber"].ToString(),
                                OIGAuditNumber = c["OIGAuditNumber"].ToString()
                            }).ToList<AuditAgency>();

                return agencies;
            }

        }
4

1 回答 1

0

该错误应该告诉您从哪里开始。

如果你启动调试器,我想你会发现机构是一个 IEnumberable,但不是一个 IQueryable

通过将 SearchAgencies 的返回类型从 IQueryable 更改为 IEnumerable 来纠正它

或者,您可以更改 PaginatedList 的类型以接受 IEnumberables 而不是 IQueryables。这可能更安全,因为 IQueryable 继承自 IEnumerable

(有关两者的区别,请参阅 http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspxIQueryable、List、IEnumerator 之间的差异?)

于 2013-06-02T08:41:05.297 回答