Вопрос

I am running EntityFramework5 with Code-First and Enabled Migration with package manager console. After enabled migration only Configuration.cs file was added to Migrations folder, not InitialCreate.cs.

I change my class from

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; }
}

to

 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; }
}

How can I fix it?

Note:

1.I am new in migration database.

2.Business Objects files and DbContext class are different class libraries.

Это было полезно?

Решение

Add the initial migration manually by using add-migration "initial" in the package manager console. If it still doesn't create a migration file, then manually delete your database and the migrations folder and do enable-migrations followed by add-migration "initial" this should work.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top