LINQ - the data source does not support server-side data paging

Asked By anjali on 24-Aug-11 06:18 AM
              DataSet xmlDS= new DataSet();
              var   Query = (from t1 in xmlDS.Tables["pricing-sum"].AsEnumerable()
                   join t2 in xmlDS.Tables["fax"].AsEnumerable() on t1.Field<Int32>("solution") equals t2.Field<Int32>("solution")
                   join t3 in xmlDS.Tables["seg"].AsEnumerable() on t2.Field<Int32>("fax-Id") equals t3.Field<Int32>("fax-Id")
                   join t4 in xmlDS.Tables["pax"].AsEnumerable() on t2.Field<Int32>("solution") equals t4.Field<Int32>("solution")
                   join t5 in xmlDS.Tables["paxinfo"].AsEnumerable() on t4.Field<Int32>("paxId") equals t5.Field<Int32>("paxId")
                   join t6 in xmlDS.Tables["pricing"].AsEnumerable() on t5.Field<Int32>("paxId") equals t6.Field<Int32>("paxId")
                   join t7 in xmlDS.Tables["pricinginfo"].AsEnumerable() on t6.Field<Int32>("pricingId") equals t7.Field<Int32>("pricingId")
                   join t8 in xmlDS.Tables["segment"].AsEnumerable() on t3.Field<Int32>("segments") equals t8.Field<Int32>("segments")
                   where t8.Field<string>("departure") == depart && t8.Field<string>("arrival") == arrival
                   select new
                   {   
                     f_Id=t2.Field<Int32>("fax_Id"),
                     f_number = t8.Field<string>("fax-number"),                    
                     departure= t8.Field<string>("departure-airport"),
                     arrival=t8.Field<string>("arrival-airport"),
                  
                   }
            );
              GridView2.Visible = true;
              GridView2.DataSource = Query;
              GridView2.DataBind();

And I got an error as the data source does not support server-side data paging
Please Help me urgent
TSN ... replied to anjali on 24-Aug-11 06:22 AM
hi..

You can't use an IQueryable object to data bind to a GridView and still use Paging and Sorting. You must return a List to the GridView using the ToList() method.

See this DevToolShed Article for more information:
http://www.devtoolshed.com/content/gridview-objectdatasource-linq-paging-and-sorting

Jitendra Faye replied to anjali on 24-Aug-11 06:22 AM

A simple ToList() on your result var should work.



Also see this blog post
.



Like this-


var   Query = (from t1 in xmlDS.Tables["pricing-sum"].AsEnumerable()
           join t2 in xmlDS.Tables["fax"].AsEnumerable() on t1.Field<Int32>("solution") equals t2.Field<Int32>("solution")
           join t3 in xmlDS.Tables["seg"].AsEnumerable() on t2.Field<Int32>("fax-Id") equals t3.Field<Int32>("fax-Id")
           join t4 in xmlDS.Tables["pax"].AsEnumerable() on t2.Field<Int32>("solution") equals t4.Field<Int32>("solution")
           join t5 in xmlDS.Tables["paxinfo"].AsEnumerable() on t4.Field<Int32>("paxId") equals t5.Field<Int32>("paxId")
           join t6 in xmlDS.Tables["pricing"].AsEnumerable() on t5.Field<Int32>("paxId") equals t6.Field<Int32>("paxId")
           join t7 in xmlDS.Tables["pricinginfo"].AsEnumerable() on t6.Field<Int32>("pricingId") equals t7.Field<Int32>("pricingId")
           join t8 in xmlDS.Tables["segment"].AsEnumerable() on t3.Field<Int32>("segments") equals t8.Field<Int32>("segments")
           where t8.Field<string>("departure") == depart && t8.Field<string>("arrival") == arrival
           select new
           {   
           f_Id=t2.Field<Int32>("fax_Id"),
           f_number = t8.Field<string>("fax-number"),          
           departure= t8.Field<string>("departure-airport"),
           arrival=t8.Field<string>("arrival-airport"),
          
           }
        ).ToList();


Try this and let me know.

anjali replied to Jitendra Faye on 24-Aug-11 08:33 AM
Hi......
Its Working fine....Now I want to check whether the field name exists or not, I mean I need concept for If condition in Linq.

Actually I am getting response from server and sometimes one or two fields may miss so I want to check whether the field exists or not...

Thanks in advance.