在.NET版本8中执行迁移的问题

问题描述 投票:0回答:1

我将软件包版本从8.0.2更改为8.0.0,但没有帮助。 项目没有错误,但是迁移出错了

错误:

实体框架工具版本“7.0.14”比运行时“8.0.0”旧。更新工具以获得最新功能和错误修复。请参阅 https://aka.ms/AAc1fbw 了解更多信息。 无法创建类型为“”的“DbContext”。尝试激活“OccupyPassway.Domain.DataBaseContext”时出现异常“无法解析类型“Microsoft.EntityFrameworkCore.DbContextOptions`1[OccupyPassway.Domain.DataBaseContext]”的服务。”尝试创建实例时抛出。有关设计时支持的不同模式,请参阅 https://go.microsoft.com/fwlink/?linkid=851728

数据库上下文:

public class DataBaseContext : DbContext
{
    public DataBaseContext(DbContextOptions<DataBaseContext> options) : base(options)
    {
        
    }

    private DbSet<Vehicle> Vehicles { get; set; } = null!;
}

配置服务:

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using OccupyPassway.Domain.Repository;
using OccupyPassway.Domain.Repository.Interface;

namespace OccupyPassway.Domain;

public static class ConfigureServices
{
    public static IServiceCollection DomainConfig(this IServiceCollection services)
    {
        services.AddDbContext<DataBaseContext>(options =>
        {
            options.UseSqlite("Data Source=DbLite.db");
        });

        services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));

        return services;
    }
}

节目:

using OccupyPassway.Domain;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.DomainConfig();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.MapControllers();
app.UseAuthentication();
app.UseAuthorization();


app.Run();
asp.net asp.net-core asp.net-web-api .net-8.0
1个回答
0
投票

奔跑

dotnet tool update --global dotnet-ef --version 8.0.0

升级实体框架工具版本。

© www.soinside.com 2019 - 2024. All rights reserved.