Code First不生成DB?

时间:2016-02-26 06:41:04

标签: c# asp.net database entity-framework

我正在学习EF,我正在关注simple-code-first示例。我按照教程中的提到做。但是当我运行应用程序时,它不会像教程中提到的那样生成数据库。专家可以告诉本教程是错误还是我做错了。

我的代码在这里:

 static void Main(string[] args)
    {

        using (var ctx = new SchoolContext())
        {
            Student stud = new Student() { Studentname = "Ram", StudentdateOfBirth = DateTime.Now.AddYears(-4) };

            ctx.Students.Add(stud);
            ctx.SaveChanges();
        }
    }

 public class SchoolContext : DbContext
{
    public SchoolContext()
        : base()
    {

    }

    public DbSet<Student> Students { get; set; }
    public DbSet<Standard> Standards { get; set; }
}

  public class Student
{
    public Student() { }

    public int StudentId { get; set; }
    public string Studentname { get; set; }
    public DateTime StudentdateOfBirth { get; set; }

    public byte[] Photo { get; set; }
    public decimal Height { get; set; }
    public float Weight { get; set; }

    public Standard Standard { get; set; }

}

 public class Standard
{
    public Standard()
    {

    }
    public int StandardId { get; set; }
    public string StandardName { get; set; }

    public ICollection<Student> Students { get; set; }
}

如果我做错了,请纠正我。

0 个答案:

没有答案