slfan
slfan

Reputation: 9129

Entity Framework 4 Query Interceptors without ADO.NET Data Services

We are using entity framework 4 to access our database. Every table has got some security related fields which we would like to check on every query (e.g. start/end date, level of security, element active or not).

Is it possible to define something like a global query interceptor that adds additional checks for the security fields? I know that query interceptors exist for WCF Data Services, but we do not use data services.

Upvotes: 0

Views: 10044

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364349

Unfortunatelly no. QueryInterceptor is feature related to WCF Data Services and whole implementation related to its usage is internal so you can't reuse it elsewhere without using WCF Data services.

Basically QueryInterceptor is just condition added to executed query so you can in the same way wrap your data access to the class which will expose method like:

public IQueryable<TEntity> GetQuery() where TEntity : IOwnedByUser
{
    return GetObjectSet<TEntity>().Where(e => e.Owner == CurrentUser.Login);
}

Upvotes: 1

Related Questions