Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

c# - CreatedOn column in Entity Framework 6

After upgrading to Entity Framework 6 we've implemented our own DbExecutionStrategy. In addition to existing SqlAzureExecutionStrategy our strategy also logs exceptions. As turned out, every 15-30 minutes Entity Framework throws internal SqlException System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'CreatedOn'. It's an internal error. Seems like EF does some regular checks if CreatedOn column exists on some table. Is there any elegant way to prevent this exception to be thrown?

Here is a call stack:

   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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In a past Entity Framework used to have a column "CreatenOn" in __MigrationHistory table.

Every time the AppDomain starts it checks if Migration is required the the database. EF actually tries to read "CreatedOn" columns and obviously fails with the exception which gets logged. EF has an ugly try/catch all block around this check and if the exception is thrown (column is missing) then it doesn't try to "migrate" CreatedOn column.

There is no way at the moment to disable that check, except just not to log it...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...