I want to use WebMatrix.Data namespace
#region Assembly WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// .. \packages\Microsoft.AspNet.WebPages.Data.3.2.7\lib\net45\WebMatrix.Data.dll
with Npgsql data provider in ASP MVC Core 5.
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 does not read config from web.config. I tried according to
Add a DbProviderFactory without an App.Config
in code
System.Data.Common.DbProviderFactories.RegisterFactory("NpgSql", Npgsql.NpgsqlFactory.Instance);
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 Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.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();
}
}
According to doc it must exist:
How to use Postgres database in WebMatrix in .NET MVC Core 5?