Could not load type 'System.ComponentModel.DataAnnotations.DatabaseGeneratedOption' from assembly 'EntityFramework' error


I have an ASP.NET application which works fine using EntityFramework 4.3. I have it now use EntityFramework 6.0.2 instead. Now I am getting the error below at a line in the OnModelCreating code.

Why am I getting this error? Why is it looking for DatabaseGeneratedOption enum in EntityFramework assembly instead of System.ComponentModel.DataAnnotations? It seems .NET is confused somehow.

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
           modelBuilder.Entity<User>().Property(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
}  <== errors here

Error message:
Could not load type 'System.ComponentModel.DataAnnotations.DatabaseGeneratedOption' from assembly 'EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Accepted Answer

Have you removed all references to System.Data.Entity dll

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why