.NET6 EFCore 和 Cosmos 迁移问题。需要一些帮助。
大家好。我是 .Net 世界的新手,我面临着 Google 未能帮助我解决的问题。你是我最后的问候。
所以。我正在尝试使用 EF Core 6.0.3 从我的小型家庭控制中心项目连接到 Azure Cosmos DB
错误:
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Migrations.IMigrator'. This is often because no database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext>
object in its constructor and passes it to the base constructor for DbContext.
我的程序.cs:
builder.Services.AddDbContext<ControlCenterContext>(options =>
options.UseCosmos(builder.Configuration.GetConnectionString("DefaultConnection"), "ToDoList"));
我的 DbContext 实现:
public class ControlCenterContext : DbContext
{
public ControlCenterContext(DbContextOptions<ControlCenterContext> options) : base(options)
{
}
}
我还尝试使用 OnConfiguring 的替代而不是 Program.cs 行。
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseCosmos(
"<AccountEndpoint>",
"<accountKey>",
databaseName: "ToDoList");
没有任何帮助。每当我跑步时dotnet ef migrations add "initialSetup"
我收到上面提到的错误。
我仔细阅读了错误,正如您所看到的,我确实应用了所有必要的构造函数参数和其他添加内容...我什至尝试创建一个普通项目并再次执行相同的操作...