简体   繁体   English

ADO.NET中的过程查询

[英]Process query in ADO.NET

I want to convert the result returned by data reader to objects. 我想将数据读取器返回的结果转换为对象。 When I query the data and group it by some field, I find that I am not taking advantage of the ordered data when I try to convert it to a list of objects which each object being the set of rows matching a group by relationship. 当我查询数据并按某个字段对其进行分组时,我发现我在尝试将其转换为对象列表时并没有利用顺序数据,每个对象都是一组按关系匹配的行集合。 Using linq might help, but I find it is like regrouping the data and not taking advantage that the query result is already ordered. 使用linq可能会有所帮助,但是我发现这就像对数据进行重新分组,而不是利用查询结果已经排序的优势。 Does anyone has any suggestion? 有人有什么建议吗?

If the grouping must be done after the data has been returned from the SQL query (eg because the grouping is dynamic) then you should remove the order by from the SQL query and move it to the Linq instead. 如果必须在从SQL查询返回数据后进行分组(例如,因为分组是动态的),则应从SQL查询中删除订单,并将其移至Linq。 Otherwise, do the grouping in the SQL query along with the ordering. 否则,请在SQL查询中进行分组以及排序。 The point is, both operations should be done in the same place at the same time. 关键是,这两个操作应同时在同一地点进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM