IQueryable and IEnumerable

 



The IQueryable interface is too broad.  Its intention is to allow any LINQ expression to be translated into SQL, which is an impossible task.  It is misleading to use the IQueryable interface as part of the public API.  It should be maintained within the repository and the list converted to IEnumerable.  

The IQueryable interface therefore should not be used outside the repository.








In the collections, IEnumerable is the most generic collection.  And the IReadOnlyList, Array and IList are the most specific. 

We should always return IReadOnlyList when it comes to returning collections from public methods or properties.







Comments

Popular posts from this blog

Microservices and Service-Oriented Architecture

Version control and Continuous Integration/Continuous Deployment (CI/CD)

Principles of Clean Code