如何在 .NET MVC Core 5 中使用带有 Npgsql 的 WebMatrix 方法 [英] How to use WebMatrix methods with Npgsql in .NET MVC Core 5

查看:20
本文介绍了如何在 .NET MVC Core 5 中使用带有 Npgsql 的 WebMatrix 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 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();
    }
}

根据文档它必须存在:

https://docs.microsoft.com/en-us/dotnet/api/system.data.common.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 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆