我正在使用Code-First和Enabled Migration运行EntityFramework5并使用包管理器控制台。启用迁移后,仅将Configuration.cs文件添加到Migrations文件夹,而不是InitialCreate.cs。
我改变我的班级
public class Product
{
public Product()
{
this.CreationDate = DateTime.Now;
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ProductId { get; set; }
public DateTime CreationDate { get; set; }
public string Image { get; set; }
public string ImageThubmnail { get; set; }
[ForeignKey("Category")]
public Guid CategoryId { get; set; }
public virtual Category Category { get; set; }
[ForeignKey("Company")]
public Guid CompanyId { get; set; }
public virtual Company Company { get; set; }
}
至
public class Product
{
public Product()
{
this.CreationDate = DateTime.Now;
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ProductId { get; set; }
public DateTime CreationDate { get; set; }
public string Name { get; set; }
public string Image { get; set; }
public string ImageThubmnail { get; set; }
[ForeignKey("Category")]
public Guid CategoryId { get; set; }
public virtual Category Category { get; set; }
[ForeignKey("Company")]
public Guid CompanyId { get; set; }
public virtual Company Company { get; set; }
}
我该如何解决?
笔记:
1.我是迁移数据库的新手。
2.Business Objects 文件和DbContext 类是不同的类库。