基于ASP.NET Core中的现有数据库创建实体框架模型

Asa*_*ase 5 c# asp.net-mvc entity-framework scaffolding asp.net-core

我正在尝试基于ASP.NET Core中的现有数据库创建实体框架模型.我不能让Scaffold-DbContext工作!我搜索了Stackoverflow和其他网站,看看我的ASP.NET核心Web应用程序项目中的包是不正确的,但我仍然无法使其工作.在程序包管理器控制台中运行Scaffold-DbContext时出现以下错误:

PM> Scaffold-DbContext "Server=.;Database=TravelAgency;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
System.AggregateException: Ett eller flera fel har uppst�tt. ---> System.MethodAccessException: Ett f�rs�k av metoden Microsoft.EntityFrameworkCore.Scaffolding.Configuration.Internal.ModelConfiguration.get_EntityConfigurations() 
att komma �t metoden Microsoft.EntityFrameworkCore.Metadata.Internal.EntityTypeNameComparer..ctor() misslyckades.    vid Microsoft.EntityFrameworkCore.Scaffolding.Configuration.Internal.ModelConfiguration.get_EntityConfigurations() 
Run Code Online (Sandbox Code Playgroud)

抱歉,我没有找到在英语包管理器控制台中显示错误的方法.它与System.AggregateException有关:发生了一个或多个错误.我的project.json文件看起来像这样:

{
  "buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
  },
  "dependencies": {
"EntityFramework": "6.1.3",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
  "type": "build",
  "version": "1.0.0-preview2-final"
},
"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": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
  "type": "build",
  "version": "1.0.0-preview2-final"
},
"NuGet.CommandLine": "3.5.0"
  },
  "frameworks": {

"net461": {}

  },

  "publishOptions": {
"include": [
  "wwwroot",
  "**/*.cshtml",
  "appsettings.json",
  "web.config"
]
  },
  "runtimeOptions": {
"configProperties": {
  "System.GC.Server": true
}
  },
  "scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },
  "tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
  "version": "1.0.0-preview2-final",
  "imports": [
    "portable-net45+win8"
  ]
}
  },
  "userSecretsId": "aspnet-TravelAgencyApplication-3fa3cffa-93a0-470d-b08a-145e604eb5f7"
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!最诚挚的问候,阿提拉

dde*_*ral 0

您应该尝试运行以下命令。

Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
Run Code Online (Sandbox Code Playgroud)

这是有关将数据库逆向工程到模型中的官方文档。确保您按照此链接安装了正确的软件包。