简体   繁体   中英

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

I have used below command to create the 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.

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

I have done lots of research. Not able to solve this issue.I am using asp.net core 1.1

here is the project.json file

    {
  "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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM