简体   繁体   English

如何在asp.net核心1.1中更新现有的dbcontext

[英]How to update the existing dbcontext in asp.net core 1.1

I have used below command to create the dbcontext 我使用下面的命令来创建dbcontext

Scaffold-DbContext "Data Source=SANPC;Initial Catalog=EMAKITI;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Data

The above command successfully created the dbcontext with all table. 上面的命令使用所有表成功创建了dbcontext。

Now, I have change some column of table and used the below command to update 现在,我已经更改了一些表的列并使用下面的命令进行更新

Scaffold-DbContext -Connection "Data Source=SANPC;Initial Catalog=EMAKITI;Integrated Security=True;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Entity -context EmakitiContext -Project DataBase -force

The above command gives me a error 上面的命令给了我一个错误

The specified deps.json [D:\\GitAlpha\\eMikitiWebApi\\eMikitiWebApiPortal\\src\\eMikitiWebApiPortal\\bin\\Debug\\netcoreapp1.1\\eMikitiWebApiPortal.deps.json] does not exist Process finished with non-zero exit code 指定的deps.json [D:\\ GitAlpha \\ eMikitiWebApi \\ eMikitiWebApiPortal \\ src \\ eMikitiWebApiPortal \\ bin \\ Debug \\ netcoreapp1.1 \\ eMikitiWebApiPortal.deps.json]不存在使用非零退出代码完成的进程

I have done lots of research. 我做了很多研究。 Not able to solve this issue.I am using asp.net core 1.1 无法解决这个问题。我正在使用asp.net核心1.1

here is the project.json file 这是project.json文件

    {
  "dependencies": {
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
    "DataBase": "1.0.0-*",
    "UnitOfWork": "1.0.0-*",
    "ViewModel": "1.0.0-*",
    "Common": "1.0.0-*",
    "Microsoft.AspNetCore.Session": "1.1.0",
    "Microsoft.Extensions.Caching.Memory": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0",
    "System.IdentityModel.Tokens.Jwt": "5.1.2",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.1.0",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },
  "runtimes": {
    "win10-x64": {}
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

You are using code first approach and in this approach changes flow from code to database. 您正在使用代码优先方法,并且在此方法中将流程从代码更改为数据库。 Entity Frame work give us option to start from existing database with reverse engineering. 实体框架工作为我们提供了从逆向工程从现有数据库开始的选项。 When we did once reverse engineering to generate our models, after that we need to follow the migrations flow in code first approach code to database. 当我们做过一次逆向工程来生成我们的模型之后,我们需要遵循迁移流程,将代码中的第一个方法代码转换为数据库。

With this command we generatee migrations 使用此命令,我们可以生成迁移

dotnet ef migrations add InitialCreate -c SchoolContext

and with this we apply it to database. 并将此应用于数据库。

dotnet ef database update -c SchoolContext

You can learn more about this here 您可以在此处了解更多相关信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 EF Core 更新 ASP.NET 5 中的 dbcontext 脚手架? - How to update dbcontext scaffolding in ASP.NET 5 with EF Core? 如何在startup.cs的ConfigureServices方法中正确注入DbContext实例(ASP.net core 1.1)? - How to inject DbContext instance in the ConfigureServices method of startup.cs correctly (ASP.net core 1.1)? 在ASP.NET Core中支撑现有数据库(Scaffold-DbContext) - Scaffolding existing databases in ASP.NET Core (Scaffold-DbContext) 覆盖ASP.NET Core 1.1中的现有数据注释属性 - Override Existing Data Annotation Attribute in asp.net core 1.1 如何在 ASP.NET Core 中更新现有的脚手架数据库的表 - How to update a table of an existing, scaffolded database in ASP.NET Core 如何在 ASP.NET Core 中更改 userManager 的 dbContext? - How can I change the dbContext of userManager in ASP.NET Core? 如何在 ASP.NET Core 5 中使用动态 DBContext 作为参数 - How to use dynamic DBContext as parameter in ASP.NET Core 5 如何在ASP.net Core中基于环境添加DbContext - How to add DbContext based on environment in ASP.net Core 如何在ASP.NET MVC Core中获取瞬态DbContext? - How to get transient DbContext in ASP.NET MVC Core? 将ASP.NET标识集成到现有的DbContext中 - Integrating ASP.NET Identity into Existing DbContext
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM