My first steps in C# are horrible.
Now I'm trying to install Entity Framework. For doing that, I just go to the NuGet package manager, I type "Entity" and try to install the first entry, the "Microsoft.EntityFrameworkCore", version v5.0.10.
That fails with following error message:
Could not install package 'Microsoft.EntityFrameworkCore 5.0.10'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.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.
How is this possible? .NetFramework, version v4.6.1 is the default in my company, I just clicked on the first NuGet package in my search result and Visual Studio 2017 is, as far as I know, a basic IDE.
In top of that, there is no direction where to go: the error message just says "not compatible" but no mentioning of .NetFramework version being too old or too recent, the .Net Framework being too old or too recent, ...
The error message mentions "to contact the package author", but when I visit the "Project URL" of the Entity Framework (https://learn.microsoft.com/en-us/ef/core/), that website does not even mention .NetFramework.
Does anybody know the simplest way to solve this issue? (I believe installing another version of Entity framework would be advised)
Thanks in advance
I've confirmed that in VS2017 Nuget Package Manager the first entry is "Microsoft.EntityFrameworkCore" and it is wrongly indicating "Latest Stable 5.0.10" as the applicable version when searching for "Entity" while using references for a .Net 4.6 project. (NuGet should be suggesting based on suitable target dependencies)
As Richard pointed out You can use EF Core within a .Net Framework project, but the limit is EF Core 3.1 as .Net Framework is only supported up to .Net Standard 2.0. If you're using the package manager UI in VS You will want to use the drop-down for "Version:" to select "3.1.19" as this is the last version that will work with .Net Framework 4.x.
I would recommend using EF6 for .Net Framework projects rather than EF Core 3.1 as 3.1 is still missing features found in EF6. Searching for "EntityFramework" will locate "EntityFramework" which is EF6. (Odd that it doesn't seem to come up readily under the search term "Entity")
Note that if you are targeting .Net Framework 4.6.1 the end of support for this version is April 2022. You should strongly consider updating the target to 4.8, or at a minimum 4.6.2.
Edit (2023-07-06): In relation to the question about missing features with EF Core 3.1...
For me the deal breakers with EF Core 3.1 were things like the lack of Table-per-Type inheritance, (EF Core 5) and to a lesser degree Table-per-Concrete-Class (EF Core 7), and Many-to-Many relationships including without joining entity (EF Core 5) From memory there were some Linq - related querying changes, though honestly I don't recall if that was related to EF Core 3.1 or 2.1. Either way I'd already decided that EF Core 3.1 wasn't "production ready" for the systems I was working on at the time. EF Core 5 was close enough, but I settled on EF Core 6 for the first production systems with .Net Core.
Depending on your implementation there are still things in EF6 that are not supported with Core such as if you are using an EDMX designer, as well as some differences in support for existing entity configuration. For instance in EF6 you can define composite keys using the combination of [Key, Column("FKName1", Order=0)]
annotations where in EF Core you will need to map these explicitly either in OnModelCreating()
or using an IEntityTypeConfiguration
.
There are improvements that can make the transition worthwhile such as better support for things like shadow properties for Foreign Keys compared to the old .Map()
oddness in EF6.
As for which versions of EF Core I would consider using, I would say at least EF Core 6. Much of this stems from the shift in support that Microsoft is committed to with .Net Core. .Net Framework 4.8 and EF6.4 will continue to be supported for a number of years. (Framework 4.7 - 4.8 have not been given an end date yet)
When migrating to .Net Core and EF Core your organization has to be prepared to face the fact that support for the current .Net Core (And EF Core by extension) will be limited to either 18 or 36 months so support for EF Core 6 for instance will end in November 2024, where EF Core 7 will end in May 2024 (finalized once .Net Core 8 is released) So the expectation is You might select .Net Core / EF Core 6 today, but you're expected to migrated to 7 then 8 then 9 etc. etc. etc. every 1-2 years. IMHO this isn't in itself a bad thing by any stretch IF Microsoft was committing to minor releases as they are widely accepted in the development community as expecting to have no breaking changes and backwards compatibility. However they have left the door wide open with releasing major versions and can just announce breaking changes and dropping support etc. at any time. It is merely a risk, not a certainty. ;)