List, IList, IEnumerable, IQueryable, ICollection, which is most flexible return type?

Collections are not generally very useful for DAL returns, because a collection does not implicitly guarantee order. It’s just a bucket of items. An IList, on the other hand, does implicitly guarantee order. So we’re down to IEnumerable or IList. The next question would be: is the List object “live”? i.e., is it connected to the data backing so that when you add an item to the IList, it will be reflected in the DB? For LINQ-to-SQL, this is not the case. Rather, you’re supposed to attach entities to the tables. So unless you supply this additional wiring, a List is superfluous. Stick with IEnumerable.

Leave a Comment