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

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

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

 

posted @ 2015-09-23 11:21  甜菜波波  阅读(15516)  评论(0编辑  收藏  举报