0

I have the following code, I can figure why its invalid argument:

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

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

// The best overloaded method match for 'AMS.Helper.PaginatedList.PaginatedList(System.Linq.IQueryable, int, int)' has some invalid arguments C:\NexGen\AMS\DEV\Source\AMS\Controllers\AuditController.cs

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

PaginatedList Code:

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);
            }
        }
    }
}

Search Agencies Code:

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;
            }

        }
Raidri
  • 17,258
  • 9
  • 62
  • 65
Chaka
  • 1,709
  • 11
  • 33
  • 58

1 Answers1

0

The error should tell you where to start.

If you fire up the debugger, I think you'll find agencies is an IEnumberable, but not an IQueryable

correct it by changing the return type of SearchAgencies from IQueryable to IEnumerable

or alternatively, you can change the type of the PaginatedList to accept IEnumberables instead of IQueryables. this may be safer as IQueryable inherits from IEnumerable

(see http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspx or Differences between IQueryable, List, IEnumerator? for the difference between the two)

Community
  • 1
  • 1
monkeyhouse
  • 2,875
  • 3
  • 27
  • 42