I noticed that LINQ to Objects has a GroupBy method. In light of this, I was wondering if anyone can build a case for group list of objects in memory using LINQ vs having SQL Server perform the grouping?
views:
55answers:
4
+2
A:
On a large data set with properly indexed tables, SQL Server will be faster. Every time. Hands down. For smaller datasets, you might not even notice a difference.
Tim Coker
2010-07-09 18:38:08
+3
A:
Some reasons you might want to group using LINQ on the client are:
- Your objects are already in memory.
- You might want to group by different keys at different times during the lifecycle of the data, and return trips to the database might be costly.
- You might want to group by something that's inconvenient for SQL Server to calculate, such as
data.GroupBy(d => DoSomethingComplicatedWith(d))
.
Chris Farmer
2010-07-09 18:39:06
+1
A:
If you are dealing with a small set of data, performance on the client is not a concern, and going back to the database again to get the data into the format you want is not an option (or an undesirable option), then doing it in memory is fine.
In all other cases, your best option would be to let the database do this work, as it is optimized for exactly this kind of operation.
Phil Sandler
2010-07-09 18:40:43
+1
A:
There are (not too few) situations where your objects are not contained in a database.
Frank
2010-07-09 18:42:54