如何在IDbCommandTreeInterceptors和IDbCommandInterceptors之间共享状态?

时间:2018-03-07 22:50:12

标签: c# entity-framework

DbCommandTreeInterceptionContextDbCommandInterceptionContext都包含UserState属性,但不会从一个属性转移到另一个属性。 I.E.在这种情况下:

public class DummyDbCommandTreeInterceptor : IDbCommandTreeInterceptor 
{
    public void TreeCreated(DbCommandTreeInterceptionContext interceptionContext)
    {
         interceptionContext.UserState = "test";
    }
}

public class DummyDbCommandInterceptor : DbCommandInterceptor
{
    public override void ReaderExecuting(DbCommand command, 
         DbCommandInterceptionContext<DbDataReader> interceptionContext)
    {
         if (interceptionContext.UserState != "test")
         {
              throw new Exception("wtf");
         }
    }
}

将抛出异常。有没有办法在两者之间分享状态?

0 个答案:

没有答案
相关问题