0

In ASP.NET MVC 3 I would like to access at database creation time the model fields as if they were objects of DataColumn class, so that I could then modify the auto-increment setting and store it back.

My primary target is to disable the auto-incrementing (identity setting) on the primary key of a model using code first approach.

gw0
  • 1,533
  • 2
  • 12
  • 13

1 Answers1

4

This might what you need

public class MyModel
{
    [Key]
    [DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.None)]
    public int MyID { get; set; }
}
dohaivu
  • 2,038
  • 15
  • 17
  • Exactly what I was searching for! A little shorter version: [DatabaseGenerated(DatabaseGeneratedOption.None)] – gw0 Aug 29 '11 at 10:03