EF6 PrimitivePropertyConfiguration not found

entity-framework-6

Question

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?

1
2
10/22/2015 9:51:13 PM

Accepted Answer

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.

4
10/23/2015 4:57:09 PM

Popular Answer

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.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow