首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EFCore .net6宇宙迁移问题

EFCore .net6宇宙迁移问题
EN

Stack Overflow用户
提问于 2022-04-08 10:12:13
回答 2查看 533关注 0票数 2

.NET6 EFCore & Cosmos移民问题。需要帮助。

大家好啊。我是.Net的新手,我正面临一个谷歌未能帮助我解决的问题。你是我的最后一任。

所以。我正在尝试使用HomeControlCenter 6.0.3从我的小EFCore项目连接到Azure Cosmos DB

错误:

代码语言:javascript
复制
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.

我的Program.cs:

代码语言:javascript
复制
builder.Services.AddDbContext<ControlCenterContext>(options =>
options.UseCosmos(builder.Configuration.GetConnectionString("DefaultConnection"), "ToDoList"));

我的DbContext冲动:

代码语言:javascript
复制
public class ControlCenterContext : DbContext
{
    public ControlCenterContext(DbContextOptions<ControlCenterContext> options) : base(options)
    {
        
    }
}

我还尝试使用OnConfiguring的重写,而不是Program.cs行。

代码语言:javascript
复制
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder.UseCosmos(
            "<AccountEndpoint>",
            "<accountKey>",
            databaseName: "ToDoList");

什么都帮不上忙。当我运行dotnet ef migrations add "initialSetup"时,我会得到上面提到的错误。

我仔细阅读了错误,正如您所看到的,我确实应用了所有必要的构造函数参数&其他添加.我甚至试图创造一个香草的项目,并再次做同样的事.

EN

回答 2

Stack Overflow用户

发布于 2022-07-14 17:20:06

我找不到微软的任何官方消息,但是这个博客的作者说使用的迁移是不支持的:https://www.thereformedprogrammer.net/an-in-depth-study-of-cosmos-db-and-ef-core-3-0-database-provider/#1-no-migrations-can-cause-problems

这是有意义的,因为CosmosDB是一个文档数据库,所以它没有模式,它只是一堆JSON文件。当我想使用迁移来创建种子数据时,我遇到了这个问题。我唯一能想到的解决方案是创建一个单独的项目,以静态值上传种子数据。但是,这只是种子数据,而不是模式更新。

票数 1
EN

Stack Overflow用户

发布于 2022-04-08 13:12:54

这个问题有点荒谬。Cosmos没有模式,因此迁移可能不受支持,也不需要。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71795255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档