This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
We're trying to get some statistical information out of our database and for that we need to sum/count/group/etc a bunch of fields. However this LINQ query results in all records being retrieved before sum/count/etc is executed:
That query however is relatively easy in SQL itself:
Now my question is, why isn't this working? The above query translates into 'correct' SQL with LINQ2SQL (as such it is roughly the same as the SQL version). |
|
|
No, you wont have a single grouping statement generated for this because the way we have to map these LINQ grouping queries against the underlying LightSpeed grouping API in respect of potentially having to handle client side projections afterwards means we cannot process this as a single query so instead we issue an initial query to determine the matching grouping keys and then fetch the results for each group. You can handle this though with the underlying API though since you will know that it can be handled entirely server side, e.g.
|
|
|
It's a bit of a shame that both LINQ2SQL and EntityFramework do not have issues with the above linq-group-query. We solved it now by using a stored procedure. |
|