title: Return Custom Object <List T> from Entity framework and assign to Object Data Source
body: <p>I need some guidance with an issue, I am using Entity Framework 4.0, I have a DAL and BLL and am binding to ObjectDataSource on the page. </p>
  
  <p>I had to write a stored procedure using <code>PIVOT</code> and dynamic SQL to return the data from multiple entities the way I want. Now I am trying to figure out how can I get Entity Framework to return a custom object that I can bind to my <code>ObjectDataSource</code> on the page, I NEED to use a custom object or a dynamic object since the stored procedure can return any number of columns so I can't use a strongly typed class or entity and I need to be also able to bind this with an <code>ObjectDataSource</code>.</p>
  
  <p>Can someone point out a good way to do this and how to define my function? With some code examples please.</p>
  
  <p>I read that I should try to use <code>List&lt;T&gt;</code> for returning an object since EF does not support returning datatables/datasets, I have the following so far but I know this isn't correct.</p>
  
  <p>I have not worked with generics much, if you could point out how to do this I'm sure this would be helpful for a lot of people. Please provide code examples for the function and how to bind <code>ObjectDataSource</code> to the return object?   </p>
  
  <p>Your help is greatly appreciated!!</p>
  
  <p><em>Thanks for your help Richard this is what my function looks like right now based on your suggestion for using DbDataRecord</em></p>
  
  <p>C# function for <code>ObjectDataSource</code> in DAL </p>
  
  <pre><code>public List&lt;DbDataRecord&gt; GetData(int product_id)
  {
      List&lt;DbDataRecord&gt; availableProducts = new List&lt;DbDataRecord&gt;();
  
      var groupData = context.ExecuteStoreQuery&lt;DbDataRecord&gt;("exec 
    spGetProducts @ProductID={0}", product_id);
  
      availableProducts = groupData.ToList&lt;DbDataRecord&gt;();
  
      return availableProducts;
  }
  </code></pre>
  
  <p><code>ObjectDataSource</code> in ASPX page</p>
  
  <pre><code>&lt;asp:ObjectDataSource ID="ODSProductAvailability" runat="server"
          TypeName="Project.BLL.ProductBL" 
          SelectMethod="GetData"  &gt;
       &lt;SelectParameters&gt;
          &lt;asp:SessionParameter Name="product_id" SessionField="ProductID" /&gt;
       &lt;/SelectParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>Right now I'm getting this error when I access the page: </p>
  
  <blockquote>
    <p><em>The result type 'System.Data.Common.DbDataRecord' may not be abstract and must include a default constructor</em></p>
  </blockquote>
  
  <p>Is this because the <code>ExecuteStoreQuery</code> expects to be defined class or entity? How can I just create an object based on the stored procedure results and assign it that?</p>