4

I am getting an error I've never seen before in EF6 (5 or 4).

Method not found: 'System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration.HasDatabaseGeneratedOption(System.Nullable`1)'.

public class AuthorizeAttribMap : EntityTypeConfiguration<AuthorizeAttrib>
{
    public AuthorizeAttribMap()
    {
        // TAttrib //
        this.HasKey(x => x.Id);

        // Properties
        this.Property(t => t.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
        this.Property(t => t.ControllerName)
            .IsRequired()
            .HasMaxLength(100);
        this.Property(t => t.ActionName)
            .HasMaxLength(100);

        // Table & Column Mappings
        this.ToTable("AuthorizeAttrib");
        this.Property(t => t.Id).HasColumnName("Id");
        this.Property(t => t.ControllerName).HasColumnName("ControllerName");
        this.Property(t => t.ActionName).HasColumnName("ActionName");
    }
}

What am I missing?

Keith Barrows
  • 24,802
  • 26
  • 88
  • 134

2 Answers2

6

Found the "problem", or at least a fix - and I hate it!

Solution contains 22 projects and growing. We do not have DI in place for separation of concerns all of the way through our stack yet. EF references have crept up the stack giving us 16 projects referencing EF. We use TFS 2013 for source control.

After multiple check ins and gets, one of the projects appears to have picked up an older EF reference. (Really? How?) By using Nuget for the solution I removed ALL EF packages (Nuget reported all projects using the same version). Closed VS, Reopened, Added EF Nuget back to all projects, fixed references where projects broke (makes them go missing in other projects). Recompiled, ran. It all works now.

We've seen this same type of error once before with NewtonSoft.JSON.

TFS is driving me nuts with this apparent switching of Nuget references.

The fix: Remove all, add all EF Nuget references.

Keith Barrows
  • 24,802
  • 26
  • 88
  • 134
  • Thanks Keith! I'm sure this will help other SO users! :) – Maxime Rouiller Oct 23 '15 at 17:06
  • Thank you! Had same problem and removing and adding EF helped. – cichy Jan 16 '17 at 13:25
  • Same situation, errors started to occur after upgrading projects from framework 4.0 to 4.6. Entity Framework package used same version everywhere, but some of the packages.config kept `targetFramework ="net40"`. Removing and reinstalling package helped. – grudolf May 29 '17 at 15:26
  • Just to add other case where this problem occurred. In my situation the method not found was `HasIndex()`. I was using EntityFramework in multiple projects and after checking the versions I noticed that it was using version 6.2.0 in one project and a version inferior to that in other project. I removed all references, restart visual studio, add new references and it worked like a charm. – jcsmata Aug 21 '18 at 10:39
0

Just double checking your code...

You are declaring it twice on the same property. Identity AND None.

Have you tried keeping just one? I've checked other implementation and it seems like the right way to go but from what I understood, those options are mutually exclusive.

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107