title: Using LinqDataSource with linq to sharepoint for paging
body: <p>I am developing a a Sharepoint 2010 visual webpart and I am trying to use LinqDataSource in it to handle paging and sorting in a GridView. 
  I made my datacontext and entity objects with spmetal. and now this is my code:</p>
  
  <p>my mark up:</p>
  
  <pre><code>&lt;%@ Register TagPrefix="asp" Namespace="System.Web.UI.WebControls" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %&gt;
  
  &lt;asp:LinqDataSource runat="server" ID="LinqDataSource1" OnSelecting="MySelecting" /&gt;
  &lt;asp:GridView ID="GridView1" runat="server"  AllowPaging="True" PageSize="3" 
      AutoGenerateColumns="False" DataSourceID="LinqDataSource1" 
      EnableModelValidation="True"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="title" HeaderText="Title" /&gt;
  
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>and my code:</p>
  
  <pre><code>protected void MySelecting(object sender, LinqDataSourceSelectEventArgs e)
  {
  
  
      TestEntitiesDataContext dc = new TestEntitiesDataContext("http://sp/sites/test");
  
      e.Result = from item in dc.TestList
                 select new
                   {
                       title = item.Title,
                       numberField = item.NumberField.ToString()
                   };
  
  
  }
  </code></pre>
  
  <p>Now the problem is when I try to view the webpart on the site I get this error:
  <strong>Expression of type 'System.Int32' cannot be used for return type 'System.Object'</strong> </p>
  
  <p>When I deactivate paging on grid view this error disappears. </p>
  
  <p>Do you have any idea why this is happening?</p>
  
  <p>I 'd be grateful of any help.</p>