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