EF模型未在azure中更新?

时间:2015-11-11 00:24:22

标签: c# asp.net-mvc entity-framework azure database-first

我使用SQL数据库和EF(db-first)在azure中设置了一个有效的asp.net mvc6 web-app。一切都很好,直到我在数据库中添加了一些列和表。重新生成模型后,一切仍然在我的本地机器上工作正常,但在发布应用程序并使用SQLAzureMW更新数据库之后,模型中似乎不存在新列,因为我收到错误"无效专栏名称" 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的models文件夹中看到正确的edmx.diagram文件。我在那个文件夹中也看到了另一个带有项目名称的edmx.diagram(在我的例子中是datatheek2.edmx.diagram)。因为我怀疑应用程序仍然使用该初始edmx图我刚删除它,但它没有任何区别。

任何人都有任何想法?非常感谢!

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

  

[SqlException(0x80131904):列名无效&#39; SignalsComplete&#39;。   列名称无效&#39; AmountWMG&#39;。列名无效   &#39; PrescriptionsCheckedBy&#39 ;.列名无效   &#39; PrescriptionsSubmitUserId&#39 ;.列名无效   &#39; PrescriptionsSubmitDate&#39 ;.列名称无效&#39; SignalsComplete&#39;。   列名称无效&#39; TimeUntill&#39;。列名无效   &#39; SignalsCheckedBy&#39 ;.列名称无效&#39; SignalsSubmitUserId&#39;。无效   列名称&#39; SignalsSubmitDate&#39;。]
  System.Data.SqlClient.SqlConnection.OnError(SqlException异常,   Boolean breakConnection,Action 1 wrapCloseInAction) +2418094
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 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,布尔&amp; 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超时,任务&amp; task,Boolean asyncWrite,SqlDataReader   ds,Boolean describeParameterEncryptionRequest)+2064
  System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior   cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String   方法,TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext
1 c)+9
  System.Data.Entity.Infrastructure.Interception.InternalDispatcher 1.Dispatch(TTarget target, Func 3操作,TInterceptionContext interceptionContext,   行动3 executing, Action 3已执行)+72
  System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(的DbCommand   command,DbCommandInterceptionContext interceptionContext)+356
  System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(的CommandBehavior   行为)+166
  System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)       +12 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand)   entityCommand,CommandBehavior行为)+37

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

的信息。]
  System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand   entityCommand,CommandBehavior行为)+112
  System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext的   context,ObjectParameterCollection parameterValues)+744
  System.Data.Entity.Core.Objects&LT;&GT; c__DisplayClass7.b__6()       +109 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func 1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288
System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__5() +142 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func
1   操作)+189
  System.Data.Entity.Core.Objects.ObjectQuery 1.GetResults(Nullable 1   forMergeOption)+279
  System.Data.Entity.Core.Objects.ObjectQuery 1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +11 System.Data.Entity.Internal.LazyEnumerator 1.MoveNext()+ 45 System.Collections.Generic.List 1..ctor(IEnumerable 1 collection)+387   System.Linq.Enumerable.ToList(IEnumerable 1 source) +58
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
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2个参数)+157
  System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext   controllerContext,ActionDescriptor actionDescriptor,IDictionary 2 parameters) +27
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
System.Web.Mvc.Async.WrappedAsyncResult
2.CallEndDelegate(IAsyncResult)   asyncResult)+29
  System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
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
System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult的   asyncResult)+10
  System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +49
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult的   asyncResult)+10
  System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult的   asyncResult)+29
  System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +55 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult的   asyncResult)+22
  System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +45
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid
1.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)   结果)+9
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()       +545 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+155

1 个答案:

答案 0 :(得分:0)

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