无法做数据库优先模型生成

时间:2017-04-18 20:40:36

标签: c# asp.net-core .net-core entity-framework-core

这就是我的project.json的样子。

{
  "dependencies": {
    "Microsoft.AspNetCore.Diagnostics": "1.1.1",
    "Microsoft.AspNetCore.Mvc": "1.1.2",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.1",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.1",
    "Microsoft.AspNetCore.StaticFiles": "1.1.1",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.1",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.1",
    "Microsoft.Extensions.Configuration.Json": "1.1.1",
    "Microsoft.Extensions.Logging": "1.1.1",
    "Microsoft.Extensions.Logging.Console": "1.1.1",
    "Microsoft.Extensions.Logging.Debug": "1.1.1",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.1.1"
    },
    "NLog.Web.AspNetCore": "4.3.1"
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": " 1.1.0-preview4-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

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

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },
  "runtimes": {
    "win8-x64": {}
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config",
    ]
  },
  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

我正在使用VS2015更新3。

enter image description here

我安装了.NET Core 1.1.1

enter image description here

以下是相关文件夹的内容。 enter image description here

问题是我无法对数据库进行逆向工程。下面是我在运行针对ASP.NET Core项目的命令时得到的内容。

PM> Scaffold-DbContext "Server=MY-PC;Database=MyDatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models 
Startup project 'src\MyProject' is an ASP.NET Core or .NET Core project for Visual Studio 2015. This version of the Entity Framework Core Package Manager Console Tools doesn't support these types of projects.

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

您无法使用Scaffold-DbContext PM,因为此工具不支持VS 2015项目,但您可以使用dotnet ef dbcontext scaffold代替 Entity Framework Core Scaffold DbContext from Existing Database

示例:

dotnet ef dbcontext scaffold "Server=MY-PC;Database=MyDatabase;Trusted_Connection=True;" -o Models Microsoft.EntityFrameworkCore.SqlServer