This is a migrated thread and some comments may be shown as answers.

Is Group By Supported?

3 Answers 201 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brendan Enrick
Top achievements
Rank 1
Brendan Enrick asked on 12 Nov 2009, 02:41 PM
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?

3 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 13 Nov 2009, 06:00 PM
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.
0
Patrice Boissonneault
Top achievements
Rank 1
answered on 27 Mar 2012, 04:11 PM
What would this look like with the new context model?  Also, how to aggregate?
Thanks.
0
Damyan Bogoev
Telerik team
answered on 28 Mar 2012, 11:34 AM
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 >>
Tags
LINQ (LINQ specific questions)
Asked by
Brendan Enrick
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Patrice Boissonneault
Top achievements
Rank 1
Share this question
or