我是实体框架核心的新手,我想在asp.net核心中使用实体框架核心。但是,当我添加迁移firstMigration时,它总是显示以下错误:
D:\ OwnLearnings \ EFCore \ AspNetCore_EFCore_001 \ src \ AspNetCore_EFCore_001 \ project.json
中的无效JSON文件Project.json:
{
"dependencies": {
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
我无法找到错误。我第一次在实体框架中遇到这种问题。提前谢谢。
答案 0 :(得分:0)
您是否缺少对依赖项中的Entity框架包的引用:
"Microsoft.EntityFrameworkCore": "1.0.0"
此外,您还需要EF Core的导入来执行迁移和更新(命令行)。这需要在工具seciton中(工具引用也需要像你所说的那样依赖于它,不要删除它)
"dependencies": {
...
},
"tools": {
..,
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"Imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
}...