entity framework 4 - IDbSet and Exposing Include method via Extension Method -
i using code-first approach ef , wanted use idbset instead of dbset unit testing mocks. problem use include() method eager loading necessary include() not exposed via idbset. saw example code using extension method expose include() doesn't seem work me; objectquery object in example null. please let me know how fix this.
public static class iqueryableextension { public static iqueryable<t> include<t>(this iqueryable<t> source, string path) t : class { objectquery<t> objectquery = source objectquery<t>; if (objectquery != null) { return objectquery.include(path); } return source; } public static iqueryable<t> include<t, tproperty>(this iqueryable<t> source, system.linq.expressions.expression<func<t, tproperty>> path) t : class { objectquery<t> objectquery = source objectquery<t>; if (objectquery != null) { return source.include(path); } return source; } }
you don't need write such extension if using ctp5. ctp5 provides include
extension iqueryable
. have reference entityframework.dll (ctp5) , add:
using system.data.entity;
your version doesn't work because converting source objectquery
of type dbquery
.
Comments
Post a Comment