当返回IOrderedEnumerable?IOrderedEnumerable

2023-09-04 07:19:59 作者:拥抱症患者i

应该 IOrderedEnumerable 作为回报纯粹键入语义价值?

Should IOrderedEnumerable be used as a return type purely for semantic value?

例如,消费在presentation层的模型时,我们怎么能知道收集是否需要订购或已订购了?

For example, when consuming a model in the presentation layer, how can we know whether the collection requires ordering or is already ordered?

怎么样在一个仓库包装与顺序存储过程通过条款的情况。如若库返回 IOrderedEnumerable ?怎么会是这样实现的?

What about in the case that a repository wraps a stored procedure with an ORDER BY clause. Should the repository return IOrderedEnumerable? And how would that be achieved?

推荐答案

我不认为这会是一个不错的主意:

I don't think it would be a good idea:

如果IOrderedEnumerable被用作返回类型为纯粹的语义价值?

Should IOrderedEnumerable be used as a return type purely for semantic value?

例如,消费在presentation层的模型时,我们怎么能知道收集是否需要订购或已订购了?

For example, when consuming a model in the presentation layer, how can we know whether the collection requires ordering or is already ordered?

什么在明知序列是有序的,如果你不知道被哪个键是有序的点?在 IOrderedEnumerable 接口的一点是要能够添加辅助排序标准,这没有多大意义,如果你不知道什么是主要标准。

What is the point in knowing that a sequence is ordered if you don't know by which key it is ordered? The point of the IOrderedEnumerable interface is to be able to add a secondary sort criteria, which doesn't make much sense if you don't know what is the primary criteria.

怎么样在一个仓库包装与ORDER BY子句的存储过程的情况。如果存储库返回IOrderedEnumerable?怎么会是这样实现的?

What about in the case that a repository wraps a stored procedure with an ORDER BY clause. Should the repository return IOrderedEnumerable? And how would that be achieved?

这是没有意义的。正如我已经说过, IOrderedEnumerable 用于添加辅助排序标准,但是当数据被存储过程返回,它已经排序,为时已晚添加第二排序标准。所有你能做的就是重新梳理它完全,因此调用 ThenBy 的结果不会有预期的效果。

This doesn't make sense. As I already said, IOrderedEnumerable is used to add a secondary sort criteria, but when the data is returned by the stored procedure, it is already sorted and it's too late to add a secondary sort criteria. All you can do is re-sort it completely, so calling ThenBy on the result wouldn't have the expected effect.