Azure:上下文在Code First模式下使用,代码是从EDMX生成的

Kri*_*rma 4 database connection-string azure entity-framework-6

我有MVC应用程序在本地运行良好.更新到Azure后,它开始抛出错误:

在Code First模式中使用上下文,其中包含从EDMX文件生成的用于Database First或Model First开发的代码.这将无法正常工作.要解决此问题,请不要删除引发此异常的代码行.如果您希望使用Database First或Model First,请确保Entity Framework连接字符串包含在启动项目的app.config或web.config中.

我检查了本地web.config和azure web.config之间是否有任何区别.除了凭证,一切都是一样的.它读到:

<add name="DBEntities" 
     connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;
                       provider=System.Data.SqlClient;
                       provider connection string=&quot;data source=xx;initial catalog=xx;persist security info=True;user id=xx;password=xx;MultipleActiveResultSets=True;application name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)

我使用的是EF 6.1.3,MVC5

Guy*_*ssy 7

我遇到了相同的错误消息,并设法在StackOverflow上这篇文章的帮助下解决它.

在Azure管理/ Web应用程序/ [您的Web应用程序] /配置/连接字符串中,确保3件事:

  1. 连接字符串与项目中的连接字符串具有相同的名称.

  2. 连接字符串Value包含项目中连接字符串中显示的所有元数据.我看起来像这样:

    metadata=res://\*/Models.[MyModel].csdl|res://\*/Models.[MyModel].ssdl|res://\*/Models.[MyModel].msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:[myDBServer].database.windows.net,1433;Database=[myDB];User ID=[myDBUser]@[myDBServer];Password=[myPassword];Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"

  3. 第三列(默认设置为SQL数据库)设置为" 自定义"


Kri*_*rma 0

找到了比在 Azure 连接字符串中添加所有内容更简单的解决方案。我刚刚更改了 Azure 中的连接字符串名称。有效..