entity-framework - 不支持关键字 : 'metadata' error in Azure function

标签 entity-framework azure azure-functions

我在 Azure 函数中遇到上述错误。当我尝试使用 Azure 功能中的 Entity Framework 与数据库建立连接时。

我阅读了一些文章,建议将连接类型从“SQL Server”更改为“自定义”,但在执行此操作后,我得到应用程序的配置文件不包含所需的providerName属性.错误。

enter image description here

现在我尝试了很多方法来解决这个问题,但还没有成功。

这是我的连接字符串 -

metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string='data source=*******;initial catalog=****;persist security info=True;user id=****;password=*******;MultipleActiveResultSets=True;App=EntityFramework

请帮忙。

最佳答案

您可能已经解决了您的问题,但我今天遇到了同样的问题。我解决如下。

  • 为 EF 模型创建了一个单独的项目。
  • 添加以下代码以扩展实体类

    [DbConfigurationType(typeof(DBContextConfig))]
    partial class <Entities Class Name>
    {
    
        public Entities(string connectionString)
          : base(connectionString)
        {
        }
    }
    
    public class DBContextConfig : DbConfiguration
    {
        public DBContextConfig()
        {
            SetProviderServices("System.Data.EntityClient", SqlProviderServices.Instance);
            SetDefaultConnectionFactory(new SqlConnectionFactory());
        }
    }
    
  • Azure Function 项目中的引用项目。
  • 将连接字符串添加到 Azure 门户中的“应用程序设置”,并将连接类型设置为“自定义”。

关于entity-framework - 不支持关键字 : 'metadata' error in Azure function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48619037/

相关文章:

c# - 如何获取 web api 结果的 Entity Framework 动态查询结果

entity-framework - 存储库模式如何定义 OrderBy

c# - Entity Framework 插入多对多现有 parent 的记录

c# - Entity Framework 查询缓存

node.js - 在 Azure Web 应用程序上运行 Node.js

azure - 如何在 Azure 表存储中嵌入文档

c# - 警告 : Only got partial types from assembly: Microsoft. Azure.WebJobs.Extensions.Storage

c# - 从 azure 函数运行 azure 存储过程

azure - 无法在 Azure Function 中创建编排函数

javascript - Azure 门户功能错误 : Update your NuGet package reference for Microsoft. Azure.WebJobs.Extensions.EventHubs