简体   繁体   中英

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.

I have a solution with 2 projects:

  1. one has data connection to one database and is a .NET Core project
  2. another one has data connection to a second database and it is .NET EF 4.7 project.

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. 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. 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. 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. 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.

I've tried reinstalling EntityFramework, checked app.config (provider string is there), checked if EntityFramework.SqlServer.dll is in dependencies - everything seems ok.

Is this even possible? Can the 3rd project be a Core 3.0 project? Someone mentioned that I should use .NET Standard Class Library to work with both projects, but Class library is not a console app. Please point me in the right direction...

Both 1 and 2 should be .NET Standard projects. The third should target either .NET Core or the .NET Framework.

I am afraid you can't "use" a .NET Core project from a .NET Framework project and vice versa. That's why there is the .NET Standard.

You may want to consider breaking out parts of your existing projects into class libraries that target .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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM