【发布时间】:2018-07-24 23:08:57
【问题描述】:
使用通过 EF 连接到数据库的控制台应用程序,我能够调用 Update-Database 并让它连接到数据库。但是,我在尝试将其迁移到 Azure 函数时遇到了麻烦。 here 提出了类似的问题,我怀疑解决方案可能是相同的,尽管没有太多细节说明可能是什么。
在我的控制台应用程序中,提供了以下相关配置:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<connectionStrings>
<add name="DBConnection" providerName="System.Data.SqlClient" connectionString="Server=.\SQLEXPRESS;Database=MyDB;User Id= . . ." />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
在我的 local.settings.json 中,我只有数据库连接字符串:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=...",
"AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=...",
},
"ConnectionStrings": {
"DBConnection": "Server=.\\SQLEXPRESS;Database=..."
}
}
链接问题的含义是需要提供提供者名称。我假设还需要提供其他一些 EF 配置部分。实际上,当我将 Functions 应用程序设置为启动时运行 Update-Database 时,我收到此错误:
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly
这往往意味着启动项目没有正确的 EF 配置。
因此,我的问题是,我需要在 local.settings.json 文件中进行哪些额外配置?
【问题讨论】:
-
你检查了这个链接 - stackoverflow.com/questions/38436256/… 吗?
-
很遗憾,Azure 功能是唯一可以作为创业公司运作的项目
-
您可以尝试指定
providerName和连接字符串programmatically。
标签: entity-framework azure azure-functions