【问题标题】:ASP.net Core Application Entity Framework 6 not generating databaseASP.net Core Application Entity Framework 6 不生成数据库
【发布时间】:2016-06-15 23:50:54
【问题描述】:

我创建了一个ASP.net Core Web Application (.NET Framework) 应用程序并将Entity Framework 6 添加到项目中。

我还创建了我的DB context,如下所示:

namespace application1
{

    Class _Dbcontext : DbContext
    {
       DbSet<Item> item {get; set;}
       DbSet<ItemView> itemView {get; set;}
     }
}

我创建的模型如下:

Class Item 
{
    public int ID {get; set;}
    public string Name {get; set;}
    List<ItemView> ItemViews {get; set;}
}

Class ItemView
{
   public int ID {get; set;}
   public string Name {get; set;}
   public Item item {get; set;}
}

我也跟着找到here的文章来设置项目。

当我运行项目时,数据库不会在mssqllocaldb(localdb)/ProjectsV13 中生成。

我可以通过了解如何设置 ASP.NET 核心 Web 应用程序 (.NET Framework) 模板来使用 Entity Framework 6 的帮助。

感谢您的帮助。

【问题讨论】:

  • 听起来您没有创建数据库,并假设它应该为您“生成”。应该有某事可以触发这一代,而您发布的任何代码都不会这样做。

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


【解决方案1】:

在您向数据库发出第一个请求之前不会创建数据库:登录网站或数据请求。或者您可以在 nuget 包控制台中使用特殊命令:

> update-database

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 2017-03-23
    • 2017-04-04
    • 2017-05-16
    • 1970-01-01
    相关资源
    最近更新 更多