Entity SQL Group By in EntityDataSource RRS feed

  • Question

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

         It As Products,
         Max(ListPrice) As MaxListPrice,
         Min(ListPrice) As MinListPrice)"

    What code shoould be if I use EntityDataSource control?


    • 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:


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact
    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.





    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