I am working on MVC3 app, using Entity Framework 4.1. I did LINQ query, and returned it as IEnumerable<T>. But, in controller, I have to use Include(other entity), like in ObjectSet, so I can show in view other entity values (which is associated to the one I am doing query on). I tried explicit cast from IEnumerable<T> to ObjectSet<T>, but it throws exception. Is there any way I can get ObjectSet from IEnumerable, or to include entity in IEnumerable?
Thanks in advance.
I am working on MVC3 app, using Entity Framework 4.1. I did LINQ query,
Share
If your context is still alive (if you haven’t left the using) and if you haven’t done
.ToList()you should be able to cast toObjectQuery<T>.A safer practice would be to use an extension method on
IQueryable<T>which checks if queryable is aObjectQuery<T>and if so casts toObjectQuery<T>and returns result .Include() otherwise returns the input query.