entity-frameworkcode-firstentity-framework-ctp5

Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns


Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

Preferably not using attributes.


Solution

  • If you're building your entities using the fluent interface rather than using attributes over the properties, you may be able to use the DatabaseGenerationOption class (from EntityFramework.dll, in the System.ComponentModel.DataAnnotations namespace). I've not tested it, but this is what it would look like:

    modelBuilder
        .Entity<Foo>()
        .Property(f => f.Id)
        .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);