none
Entity SQL Group By in EntityDataSource RRS feed

  • Question

  • When LinqDataSource control is configured to groupby, the object is represented by It:

    <asp:LinqDataSource
      ContextTypeName="AdventureWorksDataContext"
      TableName="Products"
      GroupBy="new(ProductCategory,Color)"
      Select="new(Key,
         It As Products,
         Max(ListPrice) As MaxListPrice,
         Min(ListPrice) As MinListPrice)"
      ID="LinqDataSource1"
      runat="server">
    </asp:LinqDataSource

    What code shoould be if I use EntityDataSource control?

    Thanks

    • Moved by Rowan Miller Thursday, November 25, 2010 12:28 AM (From:ADO.NET Entity Framework and LINQ to Entities (Pre-Release))
    Tuesday, November 23, 2010 6:44 PM

All replies

  • Hello Mark,

    You could rewrite the query in the QueryCreated event, for example:

    protected void EntityDataSource1_QueryCreated(object sender, QueryCreatedEventArgs e)
    {
      var products = e.Query.Cast<Products>();
      e.Query = from p in products
        where p.ProductID > 200    
        group p by p.ProductName into g
        select g; 
    }
    
    

    What's more, you can drag and drop a QueryExtender control:
    http://msdn.microsoft.com/en-us/library/dd537671.aspx

    Regards,


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Monday, November 29, 2010 6:52 AM
  • Hello Roahn

    I tried this solution but it returned the following error -

    "QueryCreated event returned a query of type 'ObjectQuery`1' when type 'ObjectQuery`1' is required."

    I only have one entitydatasource on my page with a listview bound to this. And on the code-behind page, I only have the QueryCreated event.

    Regards

    Benjamin

     

     

    Edit: My guess is because the return type is not a EntityType, this will not work.
    Friday, January 7, 2011 1:30 PM
  • I'm getting the same "QueryCreated event returned a query of type 'ObjectQuery`1' when type 'ObjectQuery`1' is required." 

     

    Does anybody know how to get this to work?

    Friday, January 28, 2011 10:07 PM
  • I'm having a similar problem so clearly this is not the answer. Can anyone help?
    Monday, July 25, 2011 11:07 PM