• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Interception.DbCommandInterceptionContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ScalarExecuting

 public override void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
 {
     if (!Suppress)
     {
         var rnd = Guid.NewGuid().ToString("N");
         command.CommandText = String.Format(Wrapped_Query_Tpl, command.CommandText, rnd, rnd);
         CommandText = command.CommandText;
     }
 }
开发者ID:ziyasal,项目名称:EntityFramework.InterceptorEx,代码行数:9,代码来源:WithTransactionInterceptor.cs


示例17: ScalarExecuting

		public override void ScalarExecuting(DbCommand command,
		                                     DbCommandInterceptionContext<object> interceptionContext)
		{
			if (!SuppressNoLock)
			{
				command.CommandText =
					TableAliasRegex.Replace(command.CommandText, "${tableAlias} WITH (NOLOCK)");
			}
		}
开发者ID:Teleopti,项目名称:Stardust,代码行数:9,代码来源:NoLockInterceptor.cs


示例18: ReaderExecuted

        public override void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
        {
            _stopwatch.Stop();
            if (interceptionContext.Exception != null)
                _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText);
            else
                _logger.TraceApi("SQL Database", "SchoolInterceptor.ReaderExecuted", _stopwatch.Elapsed, "Command: {0}:", command.CommandText);

            base.ReaderExecuted(command, interceptionContext);
        }
开发者ID:yanhua2002,项目名称:WingtipToys,代码行数:10,代码来源:SchoolInterceptorLogging.cs


示例19: ScalarExecuted

 public override void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
 {
     _stopwatch.Stop();
     if (interceptionContext.Exception != null) {
         _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText);
     }
     else {
         _logger.TraceApi("SQL Database", "SchoolInterceptor.ScalarExecuted", _stopwatch.Elapsed, "Command: {0}: ", command.CommandText);
     }
     base.ScalarExecuted(command, interceptionContext);
 }
开发者ID:Grayer123,项目名称:VisualStudioWork,代码行数:11,代码来源:SchoolInterceptorLogging.cs


示例20: NonQuery

        /// <summary>
        /// Sends <see cref="IDbCommandInterceptor.NonQueryExecuting" /> and
        /// <see cref="IDbCommandInterceptor.NonQueryExecuted" /> to any <see cref="IDbCommandInterceptor" />
        /// registered on <see cref="DbInterception" /> before/after making a
        /// call to <see cref="DbCommand.ExecuteNonQuery" />.
        /// </summary>
        /// <remarks>
        /// Note that the result of executing the command is returned by this method. The result is not available
        /// in the interception context passed into this method since the interception context is cloned before
        /// being passed to interceptors.
        /// </remarks>
        /// <param name="command">The command on which the operation will be executed.</param>
        /// <param name="interceptionContext">Optional information about the context of the call being made.</param>
        /// <returns>The result of the operation, which may have been modified by interceptors.</returns>
        public virtual int NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
        {
            Check.NotNull(command, "command");
            Check.NotNull(interceptionContext, "interceptionContext");

            return _internalDispatcher.Dispatch(
                command,
                (t, c) => t.ExecuteNonQuery(),
                new DbCommandInterceptionContext<int>(interceptionContext),
                (i, t, c) => i.NonQueryExecuting(t, c),
                (i, t, c) => i.NonQueryExecuted(t, c));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:26,代码来源:DbCommandDispatcher.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Interception.DbConnectionInterceptionContext类代码示例发布时间:2022-05-26
下一篇:
C# Db.DbTableMetadata类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap