Should IOrderedEnumerable
be used as a return type purely for semantic value?
For example, when consuming a model in the presentation layer, how can we know whether the collection requires ordering or is already ordered?
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:
Should IOrderedEnumerable be used as a return type purely for semantic value?
For example, when consuming a model in the presentation layer, how can we know whether the collection requires ordering or is already ordered?
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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With