【问题标题】:Entity framework works in console program but not in azure function实体框架适用于控制台程序但不适用于 azure 函数
【发布时间】:2018-11-20 07:53:32
【问题描述】:

我正在尝试构建一个解决方案架构,在该架构中我引用了一个 .net 项目,该项目包含我需要的实体框架 ORM 所需的所有代码,该实体框架 ORM 使用 Npgsql 提供程序连接到 postgres 数据库。

引用此类项目并进行查询在控制台应用程序中有效,但在 azure 函数项目中无效。

Here is a link to a solution 包含重现此错误所需的一切。在ConsoleApp1 中,使用了对eftest 的引用,并且将运行完成而不会出错。

名为FunctionApp3 的项目是失败案例。一个全新的面向.net framework 4.71的azure函数项目,引用eftest项目并查询它。如果你尝试这个项目,you will get this error

当然,当您实际安装它如此渴望的Npgsql 4.0.2 软件包时,它会是changes to this error.

我认为这是绑定重定向的问题。所以我添加了一个类似于控制台应用程序中现有的 app.config。结果是azure functions cant use app.config files,所以我不能在连接字符串中设置绑定重定向或providerName 属性。据我所知,keyword port not supported 是由于未在连接字符串中设置 providerName 造成的。

Here is a log of the full rebuild of the azure function project.

问题:如何让这个实体框架项目与 azure 函数项目一起使用?

【问题讨论】:

  • 我对 Azure 应用一无所知,但我想知道在 FunctionApp3 项目中如何处理您的 EF 特定应用设置。我的意思是来自 ConsoleApp1 app.config 的以下部分:configSectionsentityFramework/providersconnectionStrings/.../providerName。以我有限的理解,FunctionApp3 项目似乎不知道这些事情
  • 关于如何在没有 app.config 的情况下设置 providername,this example 看起来您可以使用比当前更具体的结构编写 local.settings.json 连接字符串。
  • 你看过这个帖子吗:stackoverflow.com/questions/45217166/…
  • 不,我还没有看过那个项目。谢谢,明天早上我会读一读。

标签: .net entity-framework azure-functions npgsql


【解决方案1】:

@grek40 通过将ProviderName 作为属性放在 settings.json 中,为第二个错误提供了解决方案。

更新 settings.json

{
  "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "AzureWebJobsDashboard": ""

    },
    "ConnectionStrings": {
        "DefaultConnection": {
            "ConnectionString": "Server=localhost;Port=5432;Database=ef-azf-ca-testdatabase;User Id=postgres;Password=postgres;Pooling=true;Max Auto Prepare=10;Auto Prepare Min Usages=1;"
            "ProviderName":  "Npgsql"
        }
    }
}

至于第一个问题,我不知道为什么我不能使用 Npgsql 版本 4.0.3,但没关系,因为我可以使用 4.0.2。帮助我们 Roji,你是我们唯一的希望。

【讨论】:

    猜你喜欢
    • 2019-09-05
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    相关资源
    最近更新 更多