C# 实体框架6中的CreatedOn列

C# 实体框架6中的CreatedOn列,c#,entity-framework,azure-sql-database,C#,Entity Framework,Azure Sql Database,升级到EntityFramework6之后,我们实现了自己的DbExecutionStrategy。除了现有的SqlAzureExecutionStrategy之外,我们的策略还记录异常。 事实证明,每隔15-30分钟实体框架就会抛出内部SqlException System.Data.SqlClient.SqlException(0x80131904):列名“CreatedOn”无效。 这是一个内部错误。似乎EF会定期检查某个表上是否存在CreatedOn列。是否有任何优雅的方法来防止抛出此异

升级到EntityFramework6之后,我们实现了自己的DbExecutionStrategy。除了现有的SqlAzureExecutionStrategy之外,我们的策略还记录异常。 事实证明,每隔15-30分钟实体框架就会抛出内部SqlException
System.Data.SqlClient.SqlException(0x80131904):列名“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)

在过去的实体框架中,迁移历史表中有一列“CreatenOn”

每次AppDomain启动时,它都会检查数据库是否需要迁移。EF实际上试图读取“CreatedOn”列,但显然失败了,异常被记录下来。EF在该检查周围有一个丑陋的try/catch all块,如果抛出异常(列丢失),则它不会尝试“迁移”CreatedOn列


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

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

问题是实体框架有一个try/catch块来处理这个错误,这样当这个错误发生时应用程序就不会停止工作。处理错误后,它会将应用程序返回到正常状态,就像您在自己的应用程序的try/catch块中所做的那样。因此,违反这些异常会使我的代码不必要地停止


当我调试一个复杂的程序时,打断所有异常是必要的,但我应该在不再需要它之后重置调试异常设置。希望这可以帮助其他人解决这个难以捕捉的环境问题。

我也遇到了这个错误。“…检查某个表上是否存在CreatedOn列”的可能重复项。您可以使用SQL Server Management Studio中的SQL profiler找出SQL EF发送到服务器的内容。在我的例子中,我看到
从[dbo].[uuu MigrationHistory]中选择TOP(1)[c].[CreatedOn]作为[CreatedOn]作为[c]
,这表明它与EF版本不匹配有关。它是特定的异常检查还是常见的?我的意思是,例如,如果抛出OutOfMemory或任何连接异常,它会被理解为CreatenOn列丢失,还是会正确地引发异常?因为EF是开源的,您能否指向源代码中丑陋的try/catch块。也许社区修复和拉取请求是合适的。参见第460行开始的方法