如何在.NET MVC Core 5中将WebMatrix方法与Npgsql一起使用 [英] How to use WebMatrix methods with Npgsql in .NET MVC Core 5

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

问题描述

我要使用WebMatrix.Data命名空间

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

使用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 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:

https://docs.microsoft.com/zh-cn/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,而不是

It seems you are targeting .NET Framework 4.8, not .NET 5:

//C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.8 \ System.Data.dll

// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.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中将WebMatrix方法与Npgsql一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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