Can Entity Framework 6 be used in a .NET Standard project? - entity-framework

And if not, will it be? If so, when?
I haven't been able to find any clear official information on this, and the limited information I was able to find on Stack Overflow is a year or two old.
I was able to find official information saying EF 6.3 will be able to be used in a .NET Core project, but I couldn't find a release date for it, nor am I sure what the implications for use in a .NET Standard project are.

EF 6 supports .NET Standard 2.1, which is currently supported by .NET Core 3.0 or later - no .NET Framework version. EF 6 also supports .NET 4.0 and 4.5 or later.
https://github.com/aspnet/EntityFramework6/blob/release/6.4/src/EntityFramework/EntityFramework.csproj#L6

Some clarification, since EntityFramework 6.3.0 .NET Standard 2.1 has been supported. However there is no .NET Framework version that supports .NET Standard 2.1. Comment from Microsoft:
NET Framework won't support .NET Standard 2.1 or later versions. For
more details, see the announcement of .NET Standard 2.1.
This means that a majority of all applications using EntityFramework 6.X won't be able to use the .NET Standard 2.1 project anyway.
https://learn.microsoft.com/en-us/dotnet/standard/net-standard
https://www.nuget.org/packages/EntityFramework/#

Related

How to use EF Core 6.0 with an application that uses .Net Framework?

I have a situation where an application uses various component libraries. The libraries were based on .NetStandard2.0/2.1 and internally used EF Core 3.1. For various deployment and development reasons, we now want to target EF Core 6.0, which raises the following issues.
Net Core 3.1 support runs out in December 2022 so we need to move away from it.
The application uses Net Framework functionality and cannot move to Net Core.
EF Core 6.0 does not support NetStandard, only Net 6.
Changing the library that uses EF Core to target NET 6 means that components referencing it also need to reference Net 6.
Dependencies trickle down to the application that targets Net Framework and, as a result, the application no longer builds because Net Framework is not compatible Net 6.
How can the Net Framework application use the Net 6 assembly? Or, more specifically, how can a Net Framework application use libraries that internally use EF Core 6.0?
The interface between the application (Net Framework) and the one single touch point library component (Netstandard) is very well defined. Maybe Pinvoke could solve the problem? Or something simpler that I have overlooked?
Somewhat related question: NU1202 Package Microsoft.EntityFrameworkCore 6.0.3 is not compatible with netstandard2.1
Other than process to process communication between .NET Framework and .NET 6, this is not supported (for example via a Web API or similar)
As a short term solution, you can change your .Net Standard 2.0 EF Core libraries to be multi targeted to both .Net Standard 2.0 (which will reference EF Core 3.1) and .Net 6 (which will reference EF Core 6). This will let your .Net Core apps use EF Core 6, while allowing your .Net Framework apps to use the same dlls, but to be using EF Core 3.1. I realize that EF Core 3.1 support ends December 2022, but it will keep things moving.
https://learn.microsoft.com/en-us/nuget/create-packages/multiple-target-frameworks-project-file
Btw, has Microsoft even attempted to address the fact that a .Net Framework application cannot reference .Net 6, therefore it cannot use EF Core 6? This is a major issue for us, as we were sold the idea that .Net Standard could be shared between .Net Framework and .Net Core, but this has ceased to be the case since .Net Standard 2.1 was introduced, and now MS has pushed all new features, like EF Core, to .Net 6.

How to get a .NET core 3.1 Project work with .NET 5.0 project

When .NET 5.0 was released, one of the features mentioned was the ability to create a .NET 5.0 component, that it would work with .NET 3.1, so you wouldn't have to use .net standard between different versions.
Well, I tried to use .net 3.1 with .net 5.0 and I keep getting errors. Is there something special we have to do to make these work? We have multiple applications at my company that use various versions of .NET core. from 2.2, 3.0, 3.1 to .net 5.0. We would like to create some NuGet packages for some of the reusable components, but trying to figure out how to use .net core through out these applications, I don't want to create them with .net standard.
Has anyone run into this or not?
You did not provide the errors, but despite that, it can already be said that .NET 5 does not ensure backwards compatibility. Microsoft provides information on compatibility and breaking changes here.
.NET 5 merges together .NET Framework and .NET Core, ending the burden of keeping both; the aim is to also include Mono and Xamarin (MAUI). However, it does not ensure compatibility with previous versions. This is a good article on the subject - some features were delayed to .NET 6 though.
Hence, the best ways for you to have the compatibility you want would be to use .NET Standard or, even better, migrate the applications to .NET 5, since previous versions' support will end soon. In the team I work, we made some migrations from .NET Core 3.x to .NET 5 and it was pretty straightforward.
It is worth noticing that .NET 5 is not LTS. .NET 6, on the other hand, is. More details on .NET releases and support policies here.
A .net 5.0 library/dll cannot be referenced from a .net version less than .net 5.0. .net standard 2.1 should be used for compatibility between the different versions of .net core and .net 5.0.
On another note - its probably best to update all .net core projects to 5.0 assuming this is possible. The End of Life has been reached on .net core versions <= 3.0 (not .net standard).
see here.

Where is the "System.Composition.TypedParts.dll"?

I am trying to use the ContainerConfiguration type from the Managed Extensibility Framework (MEF). According to here, it lives in "System.Composition.TypedParts.dll" which is part of .NET Framework 4.5. But I cannot find it in Add Reference for a .NET 4.5 application.
Where can I find this DLL?
It turned out to be part of MEF 2, which needs to be installed with NuGet. It's not distributed with .NET Framework.

Upgrading from the June CTP EF 4.2

We're currently developing an application that is using EF Code first (EF June 2011 CTP).
My first question is: Is it worth trying to upgrade to use a later version of EF?
Secondly, if so, does anyone know the steps involved to upgrade - when I try to install the NuGet package for EF 5.0 - beta 2, I end up with issues as the target framework is still 4.2.
Many thanks,
James.
The CTP is long time dead with no other version coming because all that stuff is currently part of .NET 4.5 beta and EF 5.0 beta. You must upgrade to those two and the upgrade will consist of re-targeting application back to .NET 4.0 / .NET 4.5, removing all dependencies to your current EF version and re-adding those dependencies for .NET 4.5 / EF 5.0.
Some time ago I wrote a blog post on this: http://blog.3d-logic.com/2012/04/11/entity-framework-zombie-a-k-a-microsoft-entity-framework-june-2011-ctp/. There is a number of issues with CTP 4.2 because of technical challenges related to shipping a .NET Framework library out of the .NET Framework (like 4.2 target). Move to .NET Framework 4.5 that contains the same feature set as EF 4.2 + bug fixes and has a go-live license. Use EF 5.0 on top of it and you will be in a better world.
Thanks for all the responses.
My main issue is that we rely heavily on ENUMs in our implementation of 4.2 code first. I attempted to migrate the project to 4.5 but ENUMs are not supported, and there is also an issue with table per hierarchy (which is easy to fix). The next move will be to upgrade to VS11 and use 5.0 - but this is a big undertaking.
#jwsadler:
Enums are supported by core EF libraries released as part of .net Framework 4.5 (e.g. System.Data.Entity.dll). To make enums work with CodeFirst/DbContext you do need EF 5.0.0 package from NuGet (use Install-Package EntityFramework -pre (-pre is important)). You need VS 11 for this since Visual Studio 2010 cannot be used to create applications that target .NET Framework 4.5. Note that when installing the nuget package on Visual Studio 11 the target version of the .NET Framework set for the project is taken into account. If you target .NET Framework 4 you will not be able to use EF5 features like enums or spatial.

Can I use Npgsql Data Provider in my .NET 4.0 project?

I have an MVC project that I would like to write in .NET 4.0
Is it possible to use Npgsql (which currently supports .net 3.5 ) if I will use it through Entity Framework, and I will limit myself to features of EF contained within 3.5?
Npgsql now supports .net 4.0 :D so question is no longer valid.