创建迁移失败。 EF Core工具早于某些版本

时间:2019-03-07 15:10:19

标签: c# entity-framework

我正在尝试为我的简单项目创建一个Init迁移。 但是我遇到下一个错误:

C:\RiderProjects\Architecture\Architecture>dotnet ef migrations add init
The EF Core tools version '2.1.8-servicing-32085' is older than that of the runtime '2.2.2-servicing-10034'. Update the tools for the latest features and bug fixes.
Unable to create an object of type 'DomainContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

没有任何意义,因为如果我们看一下我的NuGet依赖项:

enter image description here

没有较旧的Core.Tools版本-是2.2.2。

这是我的Context类(也许问题隐藏在此类之内):

public class DomainContext : DbContext
{
    private readonly IConfiguration _configuration;

    public DomainContext(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    public DbSet<Car> Car { get; set; }
    public DbSet<Company> Company { get; set; }
    public DbSet<Location> Location { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseSqlServer(_configuration.GetConnectionString("DefaultConnection"));
        }
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Company>(CompanyMapping.Config);
    }
}

有人可以建议解决方案吗? 编辑 这是.csproj文件:

 <ItemGroup>
      <PackageReference Include="EntityFramework" Version="6.2.0" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.2" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.2" />
      <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
      <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
      <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
      <PackageReference Include="SimpleInjector" Version="4.4.3" />
    </ItemGroup>

大更新

确保您具有上下文类的默认构造函数。

1 个答案:

答案 0 :(得分:0)

查看您的.csproj文件。可能在PackageReference节点中定位了较旧的版本。