Я делаю ASP. NET Базовое руководство для начинающих по Udemy. Задача заключается в создании базы данных Code First SQLite, и я хочу создать начальную миграцию, которая не выполняется. Ниже я опишу шаги, которые я сделал.
Я установил пакеты
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SQLite
Модель
public class Value
{
public int Id { get; set; }
public string Name { get; set; }
}
DbContext
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DbContext> options) : base(options) {}
public DbSet<Value> Values { get; set; }
}
Я регистрирую DataContext
как службу
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DataContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddControllers();
}
//...
}
Где конфигурация находится в файле конфигурации, это приложение. json file
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=wapp.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Теперь, когда Я делаю первый вызов миграции
dotnet ef migrations add InitialCreate
Я получаю ошибку
Здесь в виде текста
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: NWebApp.API.Data.DataContext Lifetime: Scoped ImplementationType: NWebApp.API.Data.DataContext': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Microsoft.EntityFrameworkCore.DbContext]' while attempting to activate 'NWebApp.API.Data.DataContext'.)
Unable to create an object of type 'DataContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Мой вопрос: что не так?