Entity Framework auto incrementing field, that isn't the Id

前端 未结 3 905
温柔的废话
温柔的废话 2020-12-05 13:19

I know this isn\'t the most ideal solution, but I need to add an auto incrementing field to one of my EF Code First objects. This column id NOT the Id, which is a guid.

3条回答
  •  抹茶落季
    2020-12-05 13:45

    You can annotate that property with DatabaseGenerated(DatabaseGeneratedOption.Identity). EF allows only single identity column per table.

    public class Foo
    {
        [Key]
        public Guid Id { get; set; }
    
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long Bar { get; set; }
    }
    

提交回复
热议问题