為dotnet核心asp.net運行CRUD腳手架時出錯

.net-core asp.net-core-mvc entity-framework-core

所以我正在攻擊.net核心並啟動了一個新的asp.net核心應用程序。我創建了一個.net核心類庫,並包含了對實體框架核心的引用。我已經創建了一個上下文,我正試圖在我的asp.net核心項目中使用這個上下文。當我嘗試腳手架時,我一直遇到這個錯誤:

在此處輸入圖像描述

出於搜索目的,這裡是錯誤消息:

運行所選代碼生成器時出錯:

'創建/修改DbContext時出錯,在成功編譯新程序集後沒有返回任何類型。

我過去曾多次使用實體框架用於其他asp.net網絡項目,並且在嘗試抽像出應用程序項目之外的dbContext時總是遇到問題。但是,這次我無法找到解決方法。

有沒有人見過這個錯誤?我可以提供有關我的project.json文件的更多詳細信息,但不是在這篇文章中放一個大的複制粘貼,我想我會先看看是否有人遇到過這個問題。

目前在我的網站項目上運行:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "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": {
      "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.1",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": {
      "version": "1.0.1",
      "type": "build"
    },
    "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.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.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": {
            "version": "1.0.0-preview2-final",
            "type": "build"
        },
        "DBCONTEXTPROJECT: "1.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",
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8"
      ]
    }
  },

  "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%" ]
  }
}

作為一個註釋,我試圖將我的dbContext項目配置為.netcore應用程序,以嘗試使遷移工作。我得到同樣的錯誤。我目前已將這些更改還原,現在將dbContext項目設置為.net標準。

這是我的dbContext項目設置:

{
    "version": "1.0.0-*",

    "dependencies": {
        "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
        "NETStandard.Library": "1.6.0"
    },

    "tools": {
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
    },
    "frameworks": {
        "netstandard1.6": {}
    }
}

我想我也應該說我可以完全運行DbContext。我在數據庫上運行了遷移,實際上可以訪問數據。

熱門答案

你可以做右擊控制器文件夾=>添加新項目=> Webapi控制器/等。

我的問題在這裡解決了具有讀/寫操作的控制器



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因