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