Search code examples
entity-frameworkentity-framework-4.1azure-sql-database

Entity Framework 4.1 code-first KeyAttribute as non-identity column


I've got a problem with a code-first model I've got. Data is now in the database so I can't re-seed the database using a DropCreateDatabaseIfModelChanges class, but I need to change one table so that a bigint column is not an IDENTITY(1,1). I've managed to do this using SSMS but now my EF code is saying it's out of date. This is the code for the table in question:

public class Vote {
    [Required, Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
    public long FacebookUserId { get; set; }
    [Required]
    public Entity Entity { get; set; }
}

So I've changed my table schema, and my model (which I thought was the reflection of it, but I'm obviously wrong), but EF is still saying my model is out of date, and I can't re-seed the database to get it "perfect".

Any help would be much appreciated.

Thanks,

Benjamin


Solution

  • Try add this to your OnModelCreating:

    modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
    

    That should remove the exception that model is out of date but till this time you must always synchronize model and database manually.