类型转换 IQueryable到 IOrderedQueryable
有谁知道将 IQueryable
类型转换为 IOrderedQueryable
是否存在任何潜在问题?
public IOrderedQueryable<T> ApplyFilter<T>(IOrderedQueryable<T> query)
{
// NOTE: Skip() and Take() both return IQueryable<T>
return (IOrderedQueryable<T>)query
.Skip((CurrentPage - 1) * PageSize)
.Take(PageSize);
}
尽管 IOrderedQueryable
实现了 IQueryable
而不是相反,但 IOrderedQueryable
没有自己的成员。所以这看起来并不重要,而且事实上似乎有效。
但它有可能引起问题吗?如果是的话,还有其他有效的方法吗?
Does anyone know if there's any potential issues typecasting an IQueryable<T>
to IOrderedQueryable<T>
?
public IOrderedQueryable<T> ApplyFilter<T>(IOrderedQueryable<T> query)
{
// NOTE: Skip() and Take() both return IQueryable<T>
return (IOrderedQueryable<T>)query
.Skip((CurrentPage - 1) * PageSize)
.Take(PageSize);
}
Even though IOrderedQueryable<T>
implements IQueryable<T>
and not the other way around, IOrderedQueryable<T>
has no members of its own. So it doesn't seem to matter and, in fact, appears to work.
But does it have the potential to cause problems? And, if so, is there another efficient way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论