Time to run IQueryable <T> instead of IList <T> for my web UI / web UI?
I have a layered application that starts with a repository template for accessing data and returns IQueryable to the Services level. The service layer, which includes all of the business logic, returns IList to the controllers (note: I use ASP.NET MVC for the user interface layer). The benefit of returning IQueryable at the data access level is that it allows my repositories to be extremely simple and database queries are delayed. However, I run database queries at my service level so that my unit tests are more reliable, and I don't give the controllers the flexibility to modify my queries. However, I recently encountered several situations where the delay in executing queries to the controllers would be much higher, because the controllers had to make some predictions on data that were specific to the user interface. Also, with the advent of things like oData, I began to wonder if endpoints (like the web interface or web apis) should work directly with IQueryable. What do you think? Is it time to start returning IQueryable from the service level to the user interface level? Or stick with IList?
This topic is here: To return an IQueryable <T> or not to return an IQueryable <T>, it seems to vouch for IList to return to the user interface layers, but I was wondering if things had changed due to new technologies and technologies.
I like to stick with the IQueryable interface whenever possible, the only problem is when completing complex filtering or retrying the query on demand at the controller level, if you have something like:
//DATA ACCESS public IQueryable<T> GetStudents() { return db.Students; } And in your controller you do re-cutting, because your client wants to filter out some data of this result, you will probably be tempted to do this at the controller level:
var result = obj.GetStudents().Where(d=>d...); and for me this is normal, but just for receiving images, if some other module should use the same filter, you cannot call it because it is at the controller level. Therefore, for me it is a balance between DRY, system flexibility and scalability. If you need a fully scalable system, you will need to do some or several overloads to the GetStudents () method and get rid of any repeated cropping at the controller level.