If I'm not mistaken, this must have come in version 6.1.1 of EntityFramework and it was not like that in previous versions.
I believe that a column only became auto-increment when the DatabaseGenerated
attribute was declared with the [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
signature.
I have a simple classes, like this:
public class Municipio
{
[Key]
public int Id { get; set; }
[StringLength(50)]
[Required(AllowEmptyStrings = false)]
public string Descricao { get; set; }
[StringLength(2)]
[Required(AllowEmptyStrings = false)]
public string Uf { get; set; }
}
Note that the Id
property is declared with the KeyAttribute
attribute only. However, an Autoincrement column is being generated.
How to prevent this from happening?