views:

871

answers:

1

I have a DAL that makes calls to my Entity Framework Model. The calls return things like IOrderedQueryable and IQueryable objects. Should I convert them to something more universal in my DAL, such as List? But I assume that if I don't need to enumerate through the entire collection, this could be wasteful... So whats the best approach? Just have the DAL return the IQueryable<> and convert it when I need to? Or is there something else more flexible? Thanks in Advance.

+2  A: 

I have the same question, but I am not sure what the perfect answer is. I feel like having the DAL return the IQueryable<> is actually the most flexible, because you could easily perform another LINQ query on top of that at another layer in the code (if necessary).

Another thing to consider is that when returning an IQueryable, the results are not yet loaded into memory. So what is being returned is actually the LINQ "query." Therefore, it's slightly different behavior than what people might be used to, which is when something is returned from the model, it is actually the results from the database.

In my situation, we are returning Lists (created by calling IQueryable<>.ToList()) from our DAL. If this list needs filtered, then we would create another DAL method that would return a filtered list instead. We chose this because the other layer that calls the DAL does not need to know that we're using the Entity Framework this way (no dependency introduced).

YeahStu