1

We are not ready to upgrade our whole solution to Core yet, but we are keen to start using Entity Framework 7. Our current Entity Framework is in a separate DLL project within our solution, so two questions:

  1. Can a .Net 4.8 solution call a Core dll?

  2. If we upgraded our EF dll to Core (so that we could apply the latest version of EF to it), would that be likely to break calls to Entity Framework in the rest of our code? Are there syntax changes between the .Net versions of EF and Core versions of EF?

Graham Laight
  • 4,700
  • 3
  • 29
  • 28
  • 1
    You can add it as a project reference if it's in your solution. – GH DevOps May 05 '23 at 12:40
  • @GHDevOps _what_? – CodeCaster May 05 '23 at 12:40
  • @CodeCaster to be crystal clear, the main program (.Net 4.8) cannot call a DLL that's created with ASP.NET core. Is that correct? – Graham Laight May 05 '23 at 12:43
  • 1
    I believe it can if you have both Net 4.8 installed on machine and Net 7. The calling conventions are the same, it is just the libraries that need to be available. – jdweng May 05 '23 at 12:46
  • @CodeCaster This answer (to a different question) says that you can call an ASP.CORE project from a .Net solution: https://stackoverflow.com/a/45383263/1649135 . Are you saying that a .Net project cannot call EF Core in a different project? – Graham Laight May 05 '23 at 13:02
  • The terminology and the changes over the past 5+ years are confusing, but basically, no, you can't. There was .NET Core (1.0-3.1) and there was .NET Standard (1.0-2.1) but all of that was for a migration period. The latest "lowest common denominator" was .NET Standard 2.0 (.NET Core 2.0 & .NET Framework 4.6.1) and that is **five years old**. – CodeCaster May 05 '23 at 13:08
  • 2
    EF Core 6/7 do not target .NET Framework, they do not target .NET Standard, and do not target .NET Core: they target .NET 6. You cannot reference .NET 6 assemblies from .NET Framework/Core/Standard assemblies. – CodeCaster May 05 '23 at 13:09
  • A quick view @ [nuget: Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/7.0.5#supportedframeworks-body-tab) shows up that there is no support before net6.0 – Sir Rufo May 05 '23 at 13:09
  • 1
    I use NET 6 projects in NET48 solutions. I share classes between them. You just need to target multiple frameworks and use preprocessor conditions or dupe your classes. – GH DevOps May 05 '23 at 13:36
  • @GHDevOps yes, you can multi-target code you write, but a third-party library targeting one framework cannot be installed in code targeting another, incompatible framework. – CodeCaster May 05 '23 at 14:39
  • @GHDevOps it looks as though people are not quite in agreement about what's possible. To be clear, you CAN share classes between Net 6 and Net48 projects - but can you call methods in Net 6 projects from Net48 projects? – Graham Laight May 07 '23 at 19:06
  • 1
    It is possible, depending on what the method does, you'll probably have to use preprocessors to determine the assemblies. I have business layer methods in a class library that I share between NET 3.1 and NET48 but I dupe them because it gets too difficult to read. Consider nullable references in later c# versions and the issues it will cause in a NET48 app. – GH DevOps May 08 '23 at 11:30

1 Answers1

1

Can a .Net 4.8 solution call a Core dll?

Assemblies target runtimes, and some runtimes are "covered" by multiple runtimes.

tl;dr: Entity Framework Core 6+ does not target .NET Framework, .NET Standard, nor .NET Core: it targets .NET 6. You cannot reference .NET 6 assemblies from .NET Framework (1.0-4.8)/Core (1.0-3.1)/Standard (1.0-2.1) assemblies.

Entity Framework Core compatibility:

If you try to install EF Core 7 in a .NET Framework 4.8.1 project:

Could not install package 'Microsoft.EntityFrameworkCore 7.0.5'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

So the last Entity Framework Core version you can use on .NET Framework is 3, which is ancient and is feature-wise not really comparable to Entity Framework (non-Core) 6.

If we upgraded our EF dll to Core (so that we could apply the latest version of EF to it), would that be likely to break calls to Entity Framework in the rest of our code? Are there syntax changes between the .Net versions of EF and Core versions of EF?

Only about everything. See Port from EF6 to EF Core.

For the inverse, see Can I add a reference to a .NET Framework DLL from a .NET 6 project?.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • (I posted part of this answer to https://stackoverflow.com/questions/76063149/installing-microsoft-entityframeworkcore-failed first, but that got Roomba'd) – CodeCaster May 05 '23 at 12:48
  • The only option - if you really want to use the newest EFCore, no matter what - is to wrap the whole database thing with a WebAPI/gRPC and use http requests from the old .net-fw application. Yes, it is some kind of work, so be careful with your choice – Sir Rufo May 05 '23 at 13:14