Saturday, July 27, 2019

Entity Framework - Adding Auto Increment Column [Code First]

Use the attribute "DatabaseGenerated"

Example:

    public class Device
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int DeviceId { get; set; }
        public string Language { get; set; }
        public string RegistrationId { get; set; }
        public string DeviceType { get; set; }
        public int UserNo { get; set; }
    }

No comments:

Post a Comment