开发者

Is it better to group by data at server or at client?

开发者 https://www.devze.com 2023-03-21 02:08 出处:网络
I am developing an app using c# and sql server 2008 to automate a sport club, and i almost done. Now i am making reports for my app by creating stored procedure in sql serv开发者_JS百科er that returns

I am developing an app using c# and sql server 2008 to automate a sport club, and i almost done. Now i am making reports for my app by creating stored procedure in sql serv开发者_JS百科er that returns the data fro c# app after passing some parameters, and the result of report like grouping, number of fields returned are changed depending on the sent parameters. My question is better to do the grouping in sql server and return the last result and show it in c# report or get the data without grouping or sorting and do it in c# report you know in c# reports you can make groups and chose what fields to group by

Thanks in advance.


It depends. If LINQ is an option (meaning you are using the entity framework or aren't using stored procedures), then you can programmatically change the group by in your C# code while still performing the grouping on the server.

If you cannot use LINQ/Entity model but your group by could change dynamically, perform the grouping at the application level so you can group the data however you need based on user parameters without using a billion different query options.

Otherwise, perform it on the server because that reduces bandwidth consumption, is faster in terms of transfer time, and is faster in general because SQL (and general database) grouping is much faster than what you would be doing in C#.

Here are links of interest:

  • ADO.NET Entity Framework
  • LINQ on .NET Framework Development Center


There are several competing factors:

  • It's relatively slow to pass data across a network (compared to processing it on the server where it's stored). Also, if you send too much data outbound from your SQL server, you risk saturating the network interface. SQL is designed (among other things) to be good at aggregating / grouping data. This favors grouping on the SQL Server.
  • SQL servers are the hardest layer to scale out. This favors minimizing processing on that server and offloading intensive processing to other app layers (web server, app server, client application). An alternative approach is to use a data layer that does scale well (NoSQL solutions).

For a sport club application, I strongly suspect that you will not over-burden your SQL server. If that's the case, I would do the grouping on the SQL server.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号