Entity framework 适用于控制台程序但不适用于 azure 函数
Entity framework works in console program but not in azure function
我正在尝试构建一个解决方案架构,其中我引用了一个 .net 项目,该项目包含 entity framework 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.
问题:如何让这个 entity framework 项目与 azure 函数项目一起工作?
@grek40 provided 通过将 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"
}
}
}
至于第一个问题,我不知道ide为什么我不能使用Npgsql 4.0.3 版,但没关系,因为我只能使用4.0.2。帮助我们 Roji,你是我们唯一的希望。
我正在尝试构建一个解决方案架构,其中我引用了一个 .net 项目,该项目包含 entity framework 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.
问题:如何让这个 entity framework 项目与 azure 函数项目一起工作?
@grek40 provided 通过将 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"
}
}
}
至于第一个问题,我不知道ide为什么我不能使用Npgsql 4.0.3 版,但没关系,因为我只能使用4.0.2。帮助我们 Roji,你是我们唯一的希望。