Can I intercept Entity Framework when it loads data from the database? -
we have multi-layered application, repositories based on (home-grown) genericrepository base of operations class (where t entity in model), exposes methods such getcontext(), getobjectset() , on. allow repositories inherit access context, need phone call include(), passing info through wcf service, need load related entities eagerly.
all of our entities implement interface has active bool property, , want intercept execution of query, , filter on active property, query returns entities set true.
can done? in lightswitch, built on ef, there event can capture gets fired right downwards in depths of query execution, , allows sort of filtering. can't find in ef allows this.
anyone ideas? thanks
in ef 5, include
extension method on iqueryable
, can this:
var query = dbset.where( o => o.isactive ).include( ... )
that means, don't have homecoming dbset<t>
generic repository - should ok homecoming iqueryable<t>
.
if meets requirements, can add together where
clause generic repository method:
partial class genericrepository<t> { public iqueryable<t> query( bool includeinactive = false ) { homecoming ctx.set<t>().where( o => includeinactive || o.isactive ); } }
entity-framework
No comments:
Post a Comment