Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 5 on .NET 4.0 - DatabaseGeneratedOption.Identity is undefined

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?

like image 224
Hotrodmonkey Avatar asked Aug 29 '12 18:08

Hotrodmonkey


2 Answers

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.

like image 130
Thomsen Avatar answered Oct 31 '22 15:10

Thomsen


The namespace changed in EF 5.0. Try adding this:

using System.ComponentModel.DataAnnotations.Schema;
like image 11
jrummell Avatar answered Oct 31 '22 14:10

jrummell