IQueryable vs IQueryable

2020-02-12 05:59发布

I'm simply wondering why there is a IQueryable<T> version without the generic capability ?

标签: c# iqueryable
2条回答
来,给爷笑一个
2楼-- · 2020-02-12 06:35

I imagine it's the same reason as Jon Skeet gives in Difference between IEnumerable and IEnumerable<T>? , to allow use in a foreach loop. IQuerable would be castable to IEnumerable, whereas IQueryable<T> would not.

Also see Marcin's answer about use in dynamic query building scenarios.

查看更多
老娘就宠你
3楼-- · 2020-02-12 07:00

The generic IQueryable<T> is the one you use most often in method signatures and the like. The non-generic IQueryable exist primarily to give you a weakly typed entry point primarily for dynamic query building scenarios.

by Matt Warren from LINQ: Building an IQueryable Provider - Part I

You should use generic IQueryable<T> everywhere it's possible.

查看更多
登录 后发表回答