Is Group By Supported?

4 posts, 0 answers
  1. Brendan Enrick
    Brendan Enrick avatar
    28 posts
    Member since:
    Jul 2009

    Posted 12 Nov 2009 Link to this post

    Is to possible to use a group by statement to get data grouped by certain values and have that translated into the SQL so that the grouping is performed before coming back to the application?
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 13 Nov 2009 Link to this post

    Hi Brendan Enrick,

    Yes, Telerik OpenAccess ORM translates the group by statement into a sql query and the grouping is performed by the database server. For example, the following statement is executed on the server:
    var q = from o in scope.Extent<Order>()
            group o by o.OrderDate into g
            select g;
    Unfortunately, server-side grouping could not be performed currently on non-nullable fields (value-type fields). This is scheduled for fixing and should be available in the upcoming service pack release.

    In the meantime, if you need to perform grouping on a non-nullable field, this could be done on the client by using the ToList() method. It forces the execution of the query and the grouping is done afterwards in memory:
    var q = from o in scope.Extent<Order>().ToList()
            group o by o.OrderDate into g
            select g;

    Kind regards,
    Damyan Bogoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Patrice Boissonneault
    Patrice Boissonneault avatar
    28 posts
    Member since:
    Nov 2009

    Posted 27 Mar 2012 Link to this post

    What would this look like with the new context model?  Also, how to aggregate?
    Thanks.
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 28 Mar 2012 Link to this post

    Hi Patrice,

    You should slightly modify the code snippet in order to use the Linq query with the new domain model:

    YourContextName context = new YourContextName();
    var q = from o in context.Orders
            group o by o.OrderDate into g
            select g;

    Helpful sample aggregate Linq queries example can be found in the Product SDK. Hope you will find it useful.

    If any other questions arise, do not hesitate to contact us back.

    Kind regards,
    Damyan Bogoev
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Back to Top