当前位置: 首页>>代码示例>>C#>>正文


C# Interception.DbCommandInterceptionContext类代码示例

本文整理汇总了C#中System.Data.Entity.Infrastructure.Interception.DbCommandInterceptionContext的典型用法代码示例。如果您正苦于以下问题:C# DbCommandInterceptionContext类的具体用法?C# DbCommandInterceptionContext怎么用?C# DbCommandInterceptionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DbCommandInterceptionContext类属于System.Data.Entity.Infrastructure.Interception命名空间,在下文中一共展示了DbCommandInterceptionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NonQueryExecuting

 public override void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
 {
     if (command.Parameters.Count > 0 && command.Parameters[0].Value.ToString() == "Throw")
     {
         interceptionContext.Exception = new DataException("Exception Test");
     }
 }
开发者ID:gkudel,项目名称:Testility,代码行数:7,代码来源:DbContextInterceptorError.cs

示例2: Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state

        public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state()
        {
            var objectContext = new ObjectContext();
            var dbContext = DbContextMockHelper.CreateDbContext(objectContext);

            var interceptionContext = new DbCommandInterceptionContext<string>();
            
            var mutableData = ((IDbMutableInterceptionContext<string>)interceptionContext).MutableData;
            mutableData.SetExecuted("Wensleydale");
            mutableData.SetExceptionThrown(new Exception("Cheez Whiz"));
            mutableData.UserState = new object();

            interceptionContext = interceptionContext
                .WithDbContext(dbContext)
                .WithObjectContext(objectContext)
                .AsAsync()
                .WithCommandBehavior(CommandBehavior.SchemaOnly);

            Assert.Equal(new[] { objectContext }, interceptionContext.ObjectContexts);
            Assert.Equal(new[] { dbContext }, interceptionContext.DbContexts);
            Assert.True(interceptionContext.IsAsync);
            Assert.Equal(CommandBehavior.SchemaOnly, interceptionContext.CommandBehavior);

            Assert.Null(interceptionContext.Result);
            Assert.Null(interceptionContext.OriginalResult);
            Assert.Null(interceptionContext.Exception);
            Assert.Null(interceptionContext.OriginalException);
            Assert.Null(interceptionContext.UserState);
            Assert.False(interceptionContext.IsExecutionSuppressed);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:30,代码来源:DbCommandInterceptionContextTests.cs

示例3: ScalarExecuting

 public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
 {
     if (!command.CommandText.EndsWith(" option(recompile)"))
     {
         command.CommandText += " option(recompile)";
     }
 }
开发者ID:kveratis,项目名称:EntityFrameworkSchoolSystem,代码行数:7,代码来源:RecompileDbCommandInterceptor.cs

示例4: ReaderExecuting

 public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
 {
     if (!command.CommandText.EndsWith(" option(recompile)"))
     {
         command.CommandText += " option(recompile)";
     }
 }
开发者ID:kveratis,项目名称:EntityFrameworkSchoolSystem,代码行数:7,代码来源:RecompileDbCommandInterceptor.cs

示例5: ReaderExecuting

        public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
        {
            // actually the same method overriden in the SchoolInterceptorLogging class
            bool throwTransientErrors = false;
            if (command.Parameters.Count > 0 && command.Parameters[0].Value.ToString() == "%Throw%")
            {
                throwTransientErrors = true;
                command.Parameters[0].Value = "%an%";
                command.Parameters[1].Value = "%an%";
            }

            if (throwTransientErrors)
            {
                _logger.Information("Returning transient error for command: {0}", command.CommandText);
                _counter++;

                if (_counter < 4)
                {
                    interceptionContext.Exception = CreateDummySqlException();
                }
                else
                {
                    _counter = 0;
                }
            }
        }
开发者ID:TienSFU25,项目名称:test_vs,代码行数:26,代码来源:SchoolInterceptorTransientErrors.cs

示例6: ReaderExecuted

        public override void ReaderExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext)
        {
            _stopwatch.Stop();
            if (interceptionContext.Exception != null)
            {
                LogHelper.Write(CommonLogger.DataBase, LogLevel.Error, String.Format("Exception:{1} \r\n --> Error executing command:\r\n {0}", command.CommandText, interceptionContext.Exception.ToString()));
            #if !DEBUG
                WorkPool.Append<NormalNotifyEmail>(WorkType.email_for_normalnotify,
                 new NormalNotifyEmail()
                 {
                     Message = String.Format("Exception:{1} \r\n --> Error executing command:\r\n {0}", command.CommandText, interceptionContext.Exception.ToString()),
                     Title = SiteSettings.SiteName + "--数据执行警告",
                     Recipient = "[email protected]"
                 });
            #endif
            }

            else
            {
                if (SQLTrace)
                {
                    if (_stopwatch.ElapsedMilliseconds >= logValue)
                    {
                        LogHelper.Write(CommonLogger.DataBase, LogLevel.Trace, String.Format("\r\n执行时间:{0} 毫秒 \r\n -->ReaderExecuted.Command:\r\n{1}", _stopwatch.ElapsedMilliseconds, command.CommandText));
                    }
                }
            }
            base.ReaderExecuted(command, interceptionContext);
        }
开发者ID:3guy,项目名称:GameTrans,代码行数:29,代码来源:EFIntercepterLogging.cs

示例7: NonQueryExecuting

 public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<Int32> interceptionContext)
 {
     if (!command.CommandText.EndsWith(" option(recompile)"))
     {
         command.CommandText += " option(recompile)";
     }
 }
开发者ID:kveratis,项目名称:EntityFrameworkSchoolSystem,代码行数:7,代码来源:RecompileDbCommandInterceptor.cs

示例8: NonQueryExecuting

        public override void NonQueryExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
        {

            base.NonQueryExecuting(command, interceptionContext);

            _stopwatch.Restart();

        }
开发者ID:key-value,项目名称:Eagle.Second,代码行数:8,代码来源:EFIntercepterLogging.cs

示例9: ReaderExecuting

        public override void ReaderExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext)
        {

            base.ReaderExecuting(command, interceptionContext);

            _stopwatch.Restart();

        }
开发者ID:key-value,项目名称:Eagle.Second,代码行数:8,代码来源:EFIntercepterLogging.cs

示例10: ScalarExecuting

        public override void ScalarExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
        {

            base.ScalarExecuting(command, interceptionContext);

            _stopwatch.Restart();

        }
开发者ID:key-value,项目名称:Eagle.Second,代码行数:8,代码来源:EFIntercepterLogging.cs

示例11: ReaderExecuting

 public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
 {
     if (!Suppress)
     {
         command.CommandText = TableAliasRegex.Replace(command.CommandText, "${tableAlias} WITH (NOLOCK)");
         CommandText = command.CommandText;
     }
 }
开发者ID:ziyasal,项目名称:EntityFramework.InterceptorEx,代码行数:8,代码来源:WithNoLockInterceptor.cs

示例12: NonQueryExecuting

 public override void NonQueryExecuting(
     DbCommand command,
     DbCommandInterceptionContext<Int32> interceptionContext
 )
 {
     base.NonQueryExecuting(command, interceptionContext);
     _stopwatch.Restart();
 }
开发者ID:embix,项目名称:EF6_Tutorial_ContosoUniversity,代码行数:8,代码来源:SchoolInterceptorLogging.cs

示例13: NonQueryExecuted

 public override void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
 {
     _stopwatch.Stop();
     if (interceptionContext.Exception != null)
     {
         _logger.Error(interceptionContext.Exception, "Error executing command: {0}: ", command.CommandText);
     }
     base.NonQueryExecuted(command, interceptionContext);
 }
开发者ID:MaxiGT,项目名称:DesarrolloVS,代码行数:9,代码来源:InterceptorLogging.cs

示例14: CreateInterceptionContext

 private static ScalarCommandInterceptionData CreateInterceptionContext(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) {
     return new ScalarCommandInterceptionData {
         DbCommand = command,
         DbContext = GetDbContext(interceptionContext),
         Error = interceptionContext.OriginalException,
         IsAsync = interceptionContext.IsAsync,
         Result = interceptionContext.Result
     };
 }
开发者ID:julianpaulozzi,项目名称:EntityProfiler,代码行数:9,代码来源:ProxiedProfilingInterceptor.cs

示例15: New_base_interception_context_has_no_state

        public void New_base_interception_context_has_no_state()
        {
            var interceptionContext = new DbCommandInterceptionContext();

            Assert.Empty(interceptionContext.ObjectContexts);
            Assert.Empty(interceptionContext.DbContexts);
            Assert.False(interceptionContext.IsAsync);
            Assert.Equal(CommandBehavior.Default, interceptionContext.CommandBehavior);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:DbCommandInterceptionContextTests.cs


注:本文中的System.Data.Entity.Infrastructure.Interception.DbCommandInterceptionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。