开发者

Entity Framework 4 Query Interceptors without ADO.NET Data Services

We are using entity framework 4 to access our database. Every table has got开发者_StackOverflow 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.


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜