[英]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 个项目的解决方案:
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.