I just read this question and it got me thinking of why I would need to use the IEnumerable when retrieving data. I understand the differences between IQueryable and IEnumerable, but would an IEnumerable object be better for data that allows filtering? for example, a table with the records which contain a date, so I can sort on the date.
I just read this question and it got me thinking of why I would
Share
If you have the objects in memory – not from another data source such as a database – use
IEnumerable<T>. That way the built in LINQ to Objects will work automatically.You could even extend LINQ to Objects by writing custom extension methods and using
yield returnandyield break.If you are using Entity Framework or some other system that is using
IQueryable<T>, I would keep it asIQueryable<T>until you need it as objects.