2017-03-16 67 views
1

我使用IDbCommandTreeInterceptor来处理软删除功能,并且当我必须读取所有删除的实体时,我遇到了一些情况。为此,我想分开“只读”DbContext,并希望我的拦截器不处理来自DbContext的查询。有没有可能为确切的dbContext添加拦截器或从拦截器处理它如何?IDbCommandTreeInterceptor精确DbContext

回答

2

假设你的特殊语境是类型的DontInterceptContext您可以使用interceptionContext,就像这样:

public void TreeCreated(DbCommandTreeInterceptionContext interceptionContext) 
{ 
    ... 

    if (interceptionContext.DbContexts.OfType<DontInterceptContext>().Any()) 
      return; 

检查在Any()一个属性的值也是一个选择