EF Code First方法永远不会创建数据库

时间:2018-07-16 16:06:40

标签: c# asp.net-mvc database entity-framework ef-code-first

我以前使用EF CF方法,并且效果很好。在另一台PC上,我正在制作MVC应用程序,当我使用CF方法时,永远不会创建数据库。我没有任何例外,我不知道该怎么办。

Web配置(不是完整的文档):

<connectionStrings>
   <add name = "DBSystemContext"
      connectionString = "server=LAPTOP-CNQSN67O\SQLEXPRESS; Initial Catalog=TestDB; Integrated Security=True" 
      providerName = "System.Data.SqlClient"/>
</connectionStrings>

上下文类:

public class DBSystemContext : DbContext
{
    public DBSystemContext() 
    {

    }

    public DbSet<Book> Books { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    }
}

Global.asax:

protected override void Seed(DBSystemContext context)
{
    Book b = new Book()
    {
        Name="Little Prince",
        Price=2323,
        Quantity=34
    };

    context.Books.Add(b);

    base.Seed(context);
}

0 个答案:

没有答案
相关问题