我想使用 WebMatrix.Data 命名空间
I want to use WebMatrix.Data namespace
#region Assembly WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 // .. packagesMicrosoft.AspNet.WebPages.Data.3.2.7lib et45WebMatrix.Data.dll在 ASP MVC Core 5 中使用 Npgsql 数据提供程序.
with Npgsql data provider in ASP MVC Core 5.
在 web.config 中定义为
In web.config it is defined as
<system.data> <DbProviderFactories> <clear /> <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql" /> </DbProviderFactories> </system.data>.NET 5 不从 web.config 读取配置.我按照
.NET 5 does not read config from web.config. I tried according to
添加一个没有 App.Config 的 DbProviderFactory
在代码中
System.Data.Common.DbProviderFactories.RegisterFactory("NpgSql", Npgsql.NpgsqlFactory.Instance);但是得到编译错误 RegisterFactory 方法不存在.VS2019 汇编查看器证实了这一点:
but got compile error RegisterFactory method does not exist. VS2019 assembly viewer confirms this:
#region Assembly System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.8System.Data.dll #endregion namespace System.Data.Common { public static class DbProviderFactories { public static DbProviderFactory GetFactory(string providerInvariantName); public static DbProviderFactory GetFactory(DataRow providerRow); public static DbProviderFactory GetFactory(DbConnection connection); public static DataTable GetFactoryClasses(); } }根据文档它必须存在:
docs.microsoft/en-us/dotnet/api/system.datamon.dbproviderfactories.registerfactory?view=net-5.0#System_Data_Common_DbProviderFactories_RegisterFactory_System_String_System_Data_Common_DbProviderFactory_
如何在 .NET MVC Core 5 中使用 WebMatrix 中的 Postgres 数据库?
How to use Postgres database in WebMatrix in .NET MVC Core 5?
推荐答案看来您的目标是 .NET Framework 4.8,而不是 .NET 5:
It seems you are targeting .NET Framework 4.8, not .NET 5:
//C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.8System.Data.dll
// C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.8System.Data.dll
此外,WebMatrix 是一项已停产的旧技术,其正式的支持已于 2017 年 11 月 1 日结束.因此,您不太可能在 .NET 5 上使用它.
Also, WebMatrix is an old technology which has been discontinued and whose formal support has ended on November 1st, 2017. So it is unlikely that you will get it working on .NET 5.
更多推荐
如何在 .NET MVC Core 5 中使用带有 Npgsql 的 WebMatrix 方法
发布评论