I need to use EF5 on .NET 4 and I've run into a reference issue when mapping my class with HasDatabaseGenerationOption.Identity which doesn't exist in the 4.0 version of the library.
The following is failing:
this.Property(t => t.DeploymentLogId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Does anyone know of a work around?
Using NuGet to add EntityFramework to a project that targets .NET 4.5, will add EntityFramework 5.0.
If you later change the project to target .NET 4.0, EntityFramework 5.0 is still referenced.
To fix it, use NuGet to uninstall EntityFramework and add it back, also in NuGet. This will add EntityFramework 4.4 which is the last supported version for .NET 4.0.
If it still does not work there may be some references to the specific EF version in
App.config
. These can be removed.We had that problem very recently on an old project, and what we did was just
The namespace changed in EF 5.0. Try adding this:
System.ComponentModel.DataAnnotations.Schema
has only been a part of the .NET Framework since 4.5If you're using 4.0 then Entity Framework will provide it for you. If you look at the source code of DatabaseGeneratedOption and the other files, you'll see that their code is wrapped in a conditional
Have you tried using a data annotation?