database - Azure:上下文正在 Code First 模式下使用从 EDMX 生成的代码

标签 database azure entity-framework-6 connection-string

我的 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=&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" />

我正在使用 EF 6.1.3、MVC5

最佳答案

我遇到了同样的错误消息,并在this post here on StackOverflow的帮助下设法解决了它。 .

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

  1. 连接字符串与项目中的连接字符串同名。

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

    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;"

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

关于database - Azure:上下文正在 Code First 模式下使用从 EDMX 生成的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31273718/

相关文章:

sql - 有没有办法为 Azure SQL Server 设置默认的 Azure SQL 数据库定价层

database - 数据库中已经有一个名为的对象

Java SQL 错误,找不到合适的驱动程序

mysql - 各种锦标赛/竞赛类型(联赛、阶梯、单败/双败等)的数据结构

azure - 如何将参数传递给逻辑应用中的服务总线主题名称?

azure - 我们如何使用 Terraform 配置 Azure SQL 数据库计划?

azure - 我可以获取存储在 Azure Databricks 上的文件元数据或文件统计信息吗

c# - DbContext 和范围依赖

php - 为什么我不写入我的数据库

php - 将 Wordpress 迁移到具有子目录的站点