确定是否IQueryable< T>是否已订购 [英] Determine whether an IQueryable<T> has been ordered or not
问题描述
是否有办法知道是否已订购IQueryable<T>
(使用OrderBy
或OrderbyDescending
)?
Is there a way to know if an IQueryable<T>
has been ordered (using OrderBy
or OrderbyDescending
)?
所以我知道在集合中调用OrderBy
还是ThenBy
.
So I know whether to call OrderBy
or ThenBy
on the collection.
IQueryable<Contact> contacts = Database.GetContacts();
我尝试了contacts is IOrderedQueryable<Contact>
,但这始终是正确的.
I tried contacts is IOrderedQueryable<Contact>
, but it's always true.
编辑:我只是更改了示例,上一个示例并没有真正表明我的观点.假设GetContacts
使用Entity Framework并仅返回表的所有记录.
Edit: I just changed my example, the previous one wasn't really showing my point. Assume that GetContacts
uses Entity Framework and simply returns all the records of a table.
稍后,我将几个功能应用于contacts
,我不知道这些功能的作用.他们可以对IQueryable<Contact>
进行排序或过滤.
Later on, I apply several functions to contacts
, I have no knowledge of what those functions do. They can sort or filter the IQueryable<Contact>
.
当我拿回收藏集时,我需要再次对其进行排序.为此,我需要知道是否需要调用OrderBy
或ThenBy
.因此,如果已对整个集合进行排序,我就不会对其重新排序.
When I get the collection back, I need to sort it once more. To do so, I need to know whether I need to call OrderBy
, or ThenBy
. So I don't reorder the whole collection if it has already been sorted.
推荐答案
简短的回答是否",Queryable类不维护标志,也不维护集合是否已排序,也不可以使用什么方法执行此类排序.
Short answer is no, the Queryable class doesn't maintain a flag or whether the collection is sorted nor what method may have been used to perform such a sort.
http://msdn.microsoft.com/zh-我们/library/system.linq.queryable.aspx
这篇关于确定是否IQueryable< T>是否已订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!