简体   繁体   中英

Filter on DBSet, DBSet.AsQueryable() or DBSet.AsQueryable<T>()

Should you add filtering (and eg ordering) to the DBSet object or first call DBSet.AsQueryable() or DBSet.AsQueryable()?

In which case do you need to use the next functions?

Context.Set<T>().Where<>
Context.Set<T>().AsQueryable<T>().Where<>
Context.Set<T>().AsQueryable().Where<>

There is no need to call IQueryable because DBSet<T> result is already returning as queryable.

For example this:

Context.Set<MyTable>.Where(i => i.itemId == 1) // returns IQuerable<MyTable>

will return a list of IQueryable results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM