升级到Entity Framework 6后,我们已经实现了自己的DbExecutionStrategy。除了现有的SqlAzureExecutionStrategy,我们的策略还记录异常。
事实证明, Entity Framework 每15-30分钟抛出内部SqlExceptionSystem.Data.SqlClient.SqlException (0x80131904): Invalid column name 'CreatedOn'.
这是内部错误。好像EF会定期检查某些表上是否存在CreatedOn列。有什么优雅的方法可以防止引发此异常?
这是一个调用堆栈:
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实际上尝试读取“CreatedOn”列,但显然会失败,但会记录异常。 EF在此检查周围有一个难看的try/catch所有块,并且如果抛出异常(缺少列),则它不会尝试“迁移” CreatedOn列。
目前无法禁用该检查,只是不进行记录...
关于c# - Entity Framework 6中的CreatedOn列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19646659/