本文整理汇总了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");
}
}
示例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);
}
示例3: ScalarExecuting
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
if (!command.CommandText.EndsWith(" option(recompile)"))
{
command.CommandText += " option(recompile)";
}
}
示例4: ReaderExecuting
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
if (!command.CommandText.EndsWith(" option(recompile)"))
{
command.CommandText += " option(recompile)";
}
}
示例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;
}
}
}
示例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);
}
示例7: NonQueryExecuting
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<Int32> interceptionContext)
{
if (!command.CommandText.EndsWith(" option(recompile)"))
{
command.CommandText += " option(recompile)";
}
}
示例8: NonQueryExecuting
public override void NonQueryExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
base.NonQueryExecuting(command, interceptionContext);
_stopwatch.Restart();
}
示例9: ReaderExecuting
public override void ReaderExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext)
{
base.ReaderExecuting(command, interceptionContext);
_stopwatch.Restart();
}
示例10: ScalarExecuting
public override void ScalarExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
base.ScalarExecuting(command, interceptionContext);
_stopwatch.Restart();
}
示例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;
}
}
示例12: NonQueryExecuting
public override void NonQueryExecuting(
DbCommand command,
DbCommandInterceptionContext<Int32> interceptionContext
)
{
base.NonQueryExecuting(command, interceptionContext);
_stopwatch.Restart();
}
示例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);
}
示例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
};
}
示例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);
}