EF 模型未在 azure 中更新?

EF model not updated in azure?

我已经使用 SQL 数据库和 EF(db-first)在 Azure 中设置了一个可用的 asp.net mvc6 网络应用程序。一切正常,直到我向数据库中添加了一些列和表。重新生成模型后,在我的本地计算机上一切仍然正常,但是在发布应用程序并在 azure 中更新数据库(使用 SQLAzureMW)后,模型中似乎不存在新列,因为我收到错误"invalid column name" 表示 10 列。使用未更改表格的页面仍在工作

在 visual studio 中连接到我的 Azure 帐户后,我在我的 Web.config 文件的远程视图中检查了我的连接字符串,它们对我来说似乎没问题:

<add name="DefaultConnection" 
     connectionString="Data Source=tcp:      <hidden>.database.windows.net,1433;Initial Catalog=datatheek7;User ID=<hidden>;Password=<hidden>" providerName="System.Data.SqlClient" />


<add name="datatheek7Entities" 
   connectionString="metadata=res://*/Models.datatheek7Entities.csdl|res://*/Models    .datatheek7Entities.ssdl|res://*/Models.datatheek7Entities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:<hidden>.database.windows.net,1433;Initial Catalog=datatheek7;User ID=<hidden>;Password=<hidden>;" providerName="System.Data.EntityClient" /></connectionStrings>

当我在 SSMS 中连接到 Azure 数据库时,新添加的列和表也是可见的,并且我可以在 Azure 的模型文件夹中看到正确的 edmx.diagram 文件。在那个文件夹中,我还看到了另一个带有项目名称的 edmx.diagram(在我的例子中是 datatheek2.edmx.diagram)。因为我怀疑该应用程序仍在使用我刚刚删除的初始 edmx 图,但它没有任何区别。

有人有什么想法吗?将不胜感激!

为了清晰起见,下面添加了完整的堆栈跟踪(请原谅我的格式设置):

[SqlException (0x80131904): Invalid column name 'SignalsComplete'. Invalid column name 'AmountWMG'. Invalid column name 'PrescriptionsCheckedBy'. Invalid column name 'PrescriptionsSubmitUserId'. Invalid column name 'PrescriptionsSubmitDate'. Invalid column name 'SignalsComplete'. Invalid column name 'TimeUntill'. Invalid column name 'SignalsCheckedBy'. Invalid column name 'SignalsSubmitUserId'. Invalid column name 'SignalsSubmitDate'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +2418094<br> System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +5694436 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
System.Data.SqlClient.SqlDataReader.get_MetaData() +89
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +379
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2064
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375<br> System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53<br> System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240<br> System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41<br> System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext1 c) +9
System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) +72
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) +356
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) +166
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +37

[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for

details.]
System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +112
System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +744
System.Data.Entity.Core.Objects.<>c__DisplayClass7.b__6() +109 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288<br> System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__5() +142 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func1 operation) +189
System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) +279
System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +11 System.Data.Entity.Internal.LazyEnumerator1.MoveNext() +45 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +387 System.Linq.Enumerable.ToList(IEnumerable1 source) +58<br> datatheek2.Controllers.BatchesController.Index() in C:\Users\Arne\Documents\Visual Studio 2015\Projects\datatheek2\datatheek2\Controllers\BatchesController.cs:45 lambda_method(Closure , ControllerBase , Object[] ) +62<br> System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14<br> System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +157
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27<br> System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22<br> System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49<br> System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49<br> System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225 System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10<br> System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49<br> System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +49<br> System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100<br> System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49<br> System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +44<br> System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13<br> System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49<br> System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +55 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12<br> System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49<br> System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +45<br> System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10<br> System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21<br> System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +545 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

我解决了我的问题! 我在本地向数据库添加了一些测试表并更新了模型,然后再次发布到 Azure。这些表在关联视图中显示得非常好,因此模型确实更新了,问题应该出在数据库模式中。我在 SSMS 中提取了完整的数据库,我在 azure 上发布的版本和我在本地发布的版本似乎有些不同,真的不知道为什么。在 azure 中删除完整的数据库并发布本地版本后,一切正常。