iqueryable

Returning IEnumerable<T> vs. IQueryable<T> [closed]

故事扮演 提交于 2019-11-25 21:54:31
问题 What is the difference between returning IQueryable<T> vs. IEnumerable<T> ? IQueryable<Customer> custs = from c in db.Customers where c.City == \"<City>\" select c; IEnumerable<Customer> custs = from c in db.Customers where c.City == \"<City>\" select c; Will both be deferred execution and when should one be preferred over the other? 回答1: Yes, both will give you deferred execution. The difference is that IQueryable<T> is the interface that allows LINQ-to-SQL (LINQ.-to-anything really) to work