Updated on Kisan Patel
Auto-increment column is very useful if we want a unique key for each record in the database table. This is generally treated as primary key and used to select, update, and delete records into the database table.
To specify an auto-increment column in the entity class, the property must be of Integer type (int).
Then you need to use the DatabaseGeneratedAttribute
in the following way:
NAMESPACE:
using System.ComponentModel.DataAnnotations.Schema;
CODE:
public class User { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } .... .... }