I'm using the code-first approach and because of that I do not have the .edmx file so I cannot change the StoreGeneratedPattern attribute. How do I then make EF auto-increment the IDs? (right now all IDs are zeros by default)
2 Answers
A primary key with auto-increment (default behavior) is generated if any of the following holds true:
- The class contains a property named "Id"
- The class contains a property named $className + "Id"
- The property of interest is annotated with KeyAttribute
Might it be that your property is named "ID" instead of "Id" without the Key attribute?
2 Comments
Kipras
I use the Key attribute and the property is named Id
Jaanus Varus
What is the type of the property?
int or something else?
DatabaseGeneratedAttributewithDatabaseGeneratedOptionasIdentity.