我有这个:
var points = from p in ContextDB.Points
orderby p.PointInTime descending
where p.InstanceID == instanceId
&& p.ParentPointID == null
&& p.PointTypeID == currentPointTypeID
select p;
还有这个:
var points = from p in ContextDB.Points
where p.InstanceID == instanceId
&& p.ParentPointID == null
&& p.PointTypeID == currentPointTypeID
orderby p.PointInTime descending
select p;
虽然我了解两者的用法(稍后会产生错误),但我不明白它们有何不同。
我确实在 STO 的其他地方看到过类似的问题,但恐怕我还没有得到这个问题的答案。
最佳答案
实现 IOrderedQueryable<T>
的类型包含额外的状态来保存有关排序的信息。
IQueryable<T>
通常表示稍后将执行的操作(并且可能在不同的计算机上使用完全不同的语言,例如使用 LINQ to SQL)。需要一个单独的接口(interface),因为下一个操作可能是另一个排序,这需要与第一个不同的处理(按列 A 排序,然后 B 需要定义两个 LINQ 运算符,但系统需要确保每个键都有助于整体排序)。
关于.net - IOrderedQueryable 和 IQueryable 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3501855/