【问题标题】:Error: There was an error runnig the selected code generator: 'Method not found...'错误:运行所选代码生成器时出错:“找不到方法...”
【发布时间】:2018-12-07 03:13:16
【问题描述】:

我正在从事我的小型 .NET Core 2.0 MVC 项目。我想要做的是生成带有视图的读/写控制器,但是当它搭建时,我有一个错误:

我正在使用:

  • Microsoft.AspNetCore.All v2.0.8
  • EFCore v2.2.0
  • EFCore.SqlServer v2.2.0
  • EfCore.Tools v2.2.0
  • Microsoft.NETCore.App v2.0.0
  • Microsoft.VS.Web.Code.Generation.Design v2.0.4
  • Npgsql.Entity.Framework.Core.postgreSQL v.2.1.2(我的朋友在 Postgre 中设置了本地数据库)

我的数据库是在 LocalDB 上正确设置的。

FarmDbContext.cs

namespace Farm.Models
{
public class FarmDbContext : DbContext
{
    public FarmDbContext(DbContextOptions<FarmDbContext>
        options) : base(options) { }

    public DbSet<Farm>         Farms          { get; set; }
    public DbSet<Animal>       Animals        { get; set; }
    public DbSet<Cultivation>  Cultivations   { get; set; }
    public DbSet<Dairy>        Dairies        { get; set; }
    public DbSet<Grain>        Grains         { get; set; }
    public DbSet<Machine>      Machines       { get; set; }
    public DbSet<MilkQuantity> MilkQuantities { get; set; }
    public DbSet<Silo>         Silos          { get; set; }
    public DbSet<Species>      Species        { get; set; }
    public DbSet<Worker>       Workers        { get; set; }
}
}

Startup.cs的一部分

public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<FarmDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddMvc();
    }

例如,我的 Farm.cs 模型:

namespace Farm.Models
{
public class Farm
{
    [Key]
    public int    Id                      { get; set; }
    public string Localization            { get; set; }

    public List<Animal>      Animals      { get; set; }
    public List<Worker>      Workers      { get; set; }
    public List<Machine>     Machines     { get; set; }
    public List<Silo>        Silos        { get; set; }
    public List<Cultivation> Cultivations { get; set; }
}
}

当我想从任何模型自动生成View(例如Create)时,我会遇到同样的错误。如何修复?

编辑:

当我将Microsoft.VisualStudio.Web.CodeGeneration.Design 升级到 2.2.0 版时,脚手架的工作时间比以前更长,我收到此错误:

【问题讨论】:

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


【解决方案1】:

问题解决了:

  • 将 VIsual Studio 2017 升级到版本。 15.9.3(我有 15.7)
  • 将 NETCore.App 和 AspNetCore.ALL 降级到 2.1 版
  • 将项目目标更改为 Net Core 2.1

现在,生成带有视图的控制器效果很好

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 2019-10-15
    • 2016-05-13
    • 2014-01-13
    • 1970-01-01
    • 2018-07-05
    • 2013-11-24
    • 1970-01-01
    • 2018-06-15
    相关资源
    最近更新 更多