0

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;}
}
George Mauer
  • 117,483
  • 131
  • 382
  • 612
  • What is the purpose of the int value if the Guid is the key? – Nate Nov 12 '15 at 02:55
  • @Nate client request, they want to be able to be able to talk about this one particular entity by a friendly incremented number. My entire infrastructure works with guid ids though – George Mauer Nov 12 '15 at 02:56
  • Possible duplicate of [Entity Framework auto incrementing field, that isnt the Id](http://stackoverflow.com/questions/10427540/entity-framework-auto-incrementing-field-that-isnt-the-id) – George Mauer Nov 12 '15 at 04:01

1 Answers1

1

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

Community
  • 1
  • 1
christutty
  • 952
  • 5
  • 12