0

我正在使用Code-FirstEnabled 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 类是不同的类库。

4

1 回答 1

1

使用add-migration "initial"包管理器控制台手动添加初始迁移。如果它仍然没有创建迁移文件,则手动删除您的数据库和迁移文件夹,然后执行enable-migrations此操作add-migration "initial"

于 2013-08-28T18:47:08.693 回答