我的 MVC 应用程序在本地运行良好。更新到 Azure 后,它开始抛出错误:
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project.
我检查了本地 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="data source=xx;initial catalog=xx;persist security info=True;user id=xx;password=xx;MultipleActiveResultSets=True;application name=EntityFramework""
providerName="System.Data.EntityClient" />
我正在使用 EF 6.1.3、MVC5
最佳答案
我遇到了同样的错误消息,并在this post here on StackOverflow的帮助下设法解决了它。 .
在 Azure 管理/Web 应用程序/[您的 Web 应用程序]/配置/连接字符串中,请确保 3 件事:
连接字符串与项目中的连接字符串同名。
连接字符串值包含项目中连接字符串中显示的所有元数据。我的看起来像这样:
metadata=res://\*/Models.[MyModel].csdl|res://\*/Models.[MyModel].ssdl|res://\*/Models.[MyModel] .msl;provider=System.Data.SqlClient;provider 连接字符串=“服务器=tcp:[myDBServer].database.windows.net,1433;数据库=[myDB];用户 ID=[myDBUser]@[myDBServer];密码=[myPassword];Trusted_Connection=False;Encrypt=True;连接超时=30;"
第三列(默认设置为 SQL 数据库)设置为自定义
关于database - Azure:上下文正在 Code First 模式下使用从 EDMX 生成的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31273718/