Reputation: 122072
I have a field on an entity that needs to be an auto-incrementing integer but is not the entity key (I use guids for that).
How do I decorate the field to make it an auto-incrementing id?
public class Foo {
public Guid Id {get; private set;} = Guid.NewGuid();
public int ShouldAutoIncrement {get; private set;}
}
Upvotes: 0
Views: 255
Reputation: 952
One of the related questions (Entity Framework auto incrementing field, that isn't the Id) is answered by the use of the
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
annotation
Upvotes: 1