EF 实体字段设置主键和自增

        [Key] //主键 
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  //设置自增
        public int id { get; set; }

        [ForeignKey("category")] //外键
        public int categoryid { get; set; }
        public Category category { get; set; }

 

转载于:https://www.cnblogs.com/tiancai/p/4831667.html

你可能感兴趣的:(数据库,c#,测试)