0

I am using Code first and my ID column looks like this:

    [Key]
    [Required]
    public int ID { get; set; }

Am trying to cancel the identity of some tables and cannot do it. I am using Fluent API:

.Property(b => b.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); 

and the generated code is of migration is:

     public override void Up()
     {
            AlterColumn("MyEntity", "ID", c => c.Int(nullable: false, 
             identity: false));
     }

     public override void Down()
     {
            AlterColumn("MyEntity", "ID", c => c.Int(nullable: false, 
            identity: true));
    }

But it doesn't change in the db. Any ideas please?

oshi oshi
  • 69
  • 7
  • Possible duplicate of [Entering keys manually with Entity Framework](https://stackoverflow.com/questions/18907411/entering-keys-manually-with-entity-framework) – Scrobi May 24 '17 at 08:31

1 Answers1

0

you can do it using data annotations.

[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int ID { get; set; }
Bidou
  • 7,378
  • 9
  • 47
  • 70
Reshma
  • 436
  • 3
  • 13