Tony_Henrich
Tony_Henrich

Reputation: 44095

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);
    ....
    base.OnModelCreating(modelBuilder);
}  <== errors here

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

Upvotes: 1

Views: 2013

Answers (1)

ErikEJ
ErikEJ

Reputation: 41779

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

Upvotes: 2

Related Questions