如何在.NET MVC Core 5中将WebMatrix方法与Npgsql一起使用

编程入门 行业动态 更新时间:2024-10-24 07:25:20
本文介绍了如何在.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:

docs.microsoft/zh-cn/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 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一起使用

本文发布于:2023-11-14 13:37:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   方法   如何在   NET   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!