entity framework6中的CreatedOn列

升级到Entity Framework 6后,我们实现了自己的DbExecutionStrategy 。 除了现有的SqlAzureExecutionStrategy,我们的策略还会记录exception。 事实certificate,每15-30分钟entity framework抛出内部SqlException System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'CreatedOn'. 这是一个内部错误。 如果某些表上存在CreatedOn列,EF似乎会进行一些定期检查。 是否有任何优雅的方法来防止抛出此exception?

这是一个调用堆栈:

  at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, ref Boolean dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, ref Task task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, ref Task task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 

在过去的entity framework中,曾经在__MigrationHistory表中有一列“CreatenOn”。

每次AppDomain启动时,它都会检查数据库是否需要迁移。 EF实际上会尝试读取“Cr​​eatedOn”列,但显然会因记录的exception而失败。 EF在此检查周围有一个丑陋的try / catch所有块,如果抛出exception(列缺失),那么它不会尝试“迁移”CreatedOn列。

目前没有办法禁用该检查,只是不记录它…

在我的情况下,发生此错误是因为我已将Visual Studio调试exception设置更改为在所有exception中中断(或者在默认配置之外的更多例外情况下)。 重置Visual Studio的所有设置后,错误不再发生,我的应用程序按预期正常运行。

问题是Entity Framework有一个try / catch块来处理这个错误,这样当发生这个错误时应用程序不会停止工作。 处理完错误后,它会将应用程序返回到正常状态,就像您在自己的应用程序的try / catch块中一样。 因此, 打破这些exception会使我的代码不必要地停止

在我调试复杂程序时,必须打破所有exception,但是在我不再需要它之后我应该已经重置了调试exception设置。 希望这可以帮助其他人经历同样困难的环境问题。