简体   繁体   English

如何在第三个项目中引用和使用 .NET Core 3.0 和 .NET EF 4.7 项目,并使用它们的数据库连接?

[英]How can I reference and use .NET Core 3.0 and .NET EF 4.7 projects, in a third project, and use their database connections?

I'm mainly PHP dev, recently forced into .NET.我主要是 PHP 开发人员,最近被迫使用 .NET。

I have a solution with 2 projects:我有一个包含 2 个项目的解决方案:

  1. one has data connection to one database and is a .NET Core project一个具有到一个数据库的数据连接并且是一个 .NET Core 项目
  2. another one has data connection to a second database and it is .NET EF 4.7 project.另一个有到第二个数据库的数据连接,它是 .NET EF 4.7 项目。

I want to create a console app that will allow me to work with both databases.我想创建一个控制台应用程序,让我可以使用这两个数据库。 I need those 2 projects as they already have all models and connection defined and work well on their own.我需要这 2 个项目,因为它们已经定义了所有模型和连接,并且它们自己运行良好。 I need to be able to connect to both databases, and fetch some data to output in a console.我需要能够连接到两个数据库,并获取一些数据以在控制台中输出。

So far I've created a third project, Core 3.0.到目前为止,我已经创建了第三个项目 Core 3.0。 I managed to use the 1st project data connection, but I can't possibly work out how to use the EF 4.7 project connection.我设法使用了第一个项目数据连接,但我无法弄清楚如何使用 EF 4.7 项目连接。 I'm getting this error:我收到此错误:

The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded.具有不变名称“System.Data.SqlClient”的 ADO.NET 提供程序未在计算机或应用程序配置文件中注册,或者无法加载。 See the inner exception for details.有关详细信息,请参阅内部异常。 ---> System.ArgumentException: The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers. ---> System.ArgumentException:在已注册的 .NET 数据提供程序列表中找不到指定的不变名称“System.Data.SqlClient”。

I've tried reinstalling EntityFramework, checked app.config (provider string is there), checked if EntityFramework.SqlServer.dll is in dependencies - everything seems ok.我试过重新安装 EntityFramework,检查 app.config(提供者字符串在那里),检查EntityFramework.SqlServer.dll是否在依赖项中 - 一切似乎没问题。

Is this even possible?这甚至可能吗? Can the 3rd project be a Core 3.0 project?第三个项目可以是 Core 3.0 项目吗? Someone mentioned that I should use .NET Standard Class Library to work with both projects, but Class library is not a console app.有人提到我应该使用 .NET Standard Class Library 来处理这两个项目,但 Class library 不是控制台应用程序。 Please point me in the right direction...请指出我正确的方向...

Both 1 and 2 should be .NET Standard projects. 1 和 2 都应该是 .NET Standard 项目。 The third should target either .NET Core or the .NET Framework.第三个应该针对 .NET Core 或 .NET Framework。

I am afraid you can't "use" a .NET Core project from a .NET Framework project and vice versa.恐怕您不能从 .NET Framework 项目“使用”.NET Core 项目,反之亦然。 That's why there is the .NET Standard.这就是为什么有 .NET 标准。

You may want to consider breaking out parts of your existing projects into class libraries that target .NET Standard.您可能需要考虑将现有项目的一部分分解为面向 .NET Standard 的类库。 You can then reference them from any app that is compiled against a version that is compatible with the .NET Standard version you are targeting.然后,您可以从针对与您的目标 .NET Standard 版本兼容的版本编译的任何应用程序中引用它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 .NET 2 项目中使用 .NET 4.7 程序集? - How can I use .NET 4.7 assembly in .NET 2 project? 如何将 ODBC 连接与 Visual Studio 2019 和 .NET Core 3.0 结合使用? - How can I use ODBC connections with Visual Studio 2019 and .NET Core 3.0? 如何在.net 2.0项目中使用.net 3.0类? - How can I use .net 3.0 class in .net 2.0 project? 如何在 .net 4.7 项目中使用 Unity 容器解析 EF Core 上下文 - How to resolve EF Core context with Unity container in a .net 4.7 project 我可以在我的 ApplicationLogic 项目(net standard 2.1)中的 MVC(.net core 3.0)项目中使用视图模型吗? - Can I use viewmodels in my MVC(.net core 3.0) project in my ApplicationLogic project (net standard 2.1) 如何在 Google Cloud 中使用 .Net Core 3.0 映像? - How can I use .Net Core 3.0 image in Google Cloud? 将 Web 应用项目添加到我的解决方案中,并且解决方案中的其他项目已经使用 .net 框架,我可以将 .net 核心用于新项目吗? - adding a web app project to my solution, and the other projects in the solution already use .net framework, can I use .net core for the new project? 我无法在.net 4.7项目中使用System.Runtime 4.3.0 - I can't use the System.Runtime 4.3.0 in a .net 4.7 project 如何在此代码中执行 CRUD,而无需 webforms gridview、.net core 4.7 中的数据库和数据表 - How can I do a CRUD in this code without database and datatables in webforms gridview, .net core 4.7 如何使用 .NET Core EF 即时创建数据库 - How can I create a database on the fly with .NET Core EF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM