Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should a Repository return IEnumerable<T> , IQueryable<T> or List<T>? [closed]

I'd like to make my application as flexible as possible, but not dig myself into a hole by making my Interface too specific.

What is the best object type for a repository? IEnumerable, IQueryable, or List?

The technologies I'm considering using are

  • Azure App Fabric Caching

  • Entity Framework 4.1

  • Possibly Windows Server AppFabric

like image 974
makerofthings7 Avatar asked Nov 12 '11 02:11

makerofthings7


1 Answers

It depends on whether you wish to have any future queries performed on the entity and whether these should be in memory or not:

  • If there are to be future queries and the DB should do the work return IQueryable.
  • If there are to be future queries and it is to be done in memory return IEnumerable.
  • If there are to be no further queries and all the data will need to be read return an IList, ICollection etc.
like image 195
Rich O'Kelly Avatar answered Sep 22 '22 09:09

Rich O'Kelly