views:

38

answers:

2

hiya, i have the following code but when i try and create a new IQuerable i get an error that the interface cannot be implemented, if i take away the new i get a not implemented exception, have had to jump back and work on some old ASP classic sites for past month and for the life of me i can not wake my brain up into C# mode.

Could you please have a look at below and give me some clues on where i'm going wrong:

The code is to create a list of priceItems, but instead of a categoryID (int) i am going to be showing the name as string.

        public ActionResult ViewPriceItems(int? page)
    {
        var crm = 0;
        page = GetPage(page);

        // try and create items2
        IQueryable<ViewPriceItemsModel> items2 = new IQueryable<ViewPriceItemsModel>();

        // the data to be paged,but unmodified
        var olditems = PriceItem.All().OrderBy(x => x.PriceItemID);

        foreach (var item in olditems)
        {
            // set category as the name not the ID for easier reading
            items2.Concat(new [] {new ViewPriceItemsModel {ID = item.PriceItemID,
                  Name = item.PriceItem_Name,
                  Category = PriceCategory.SingleOrDefault(
                       x => x.PriceCategoryID == item.PriceItem_PriceCategory_ID).PriceCategory_Name,
                  Display = item.PriceItems_DisplayMethod}});
        }


        crm = olditems.Count() / MaxResultsPerPage;
        ViewData["numtpages"] = crm;
        ViewData["curtpage"] = page + 1;

        // return a paged result set
        return View(new PagedList<ViewPriceItemsModel>(items2, page ?? 0, MaxResultsPerPage));
    } 

many thanks

+1  A: 

you do not need to create items2. remove the line with comment try and create items2. Use the following code. I have not tested this. But I hope this works.

var items2 = (from item in olditems
                      select new ViewPriceItemsModel
                          {
                              ID = item.PriceItemID,
                              Name = item.PriceItem_Name,
                              Category = PriceCategory.SingleOrDefault(
                                 x => x.PriceCategoryID == item.PriceItem_PriceCategory_ID).PriceCategory_Name,
                              Display = item.PriceItems_DisplayMethod
                          }).AsQueryable();
mohang
thanks for response but that wont create an Querable object just a single ViewPriceItemsModel
minus4
I changed the code to return IQueryable. Please check.
mohang
yeah a figured that thanks for your help you was spot on :-)
minus4
A: 

mohang it dont seem to work, the bit for the category allways just outputs the number, its like it just puts PriceItem into ViewPriceItemsModel without processing my code????

minus4