【问题标题】:EntityFrameworkCore.Cosmos preview 3 - Not Found ErrorEntityFrameworkCore.Cosmos 预览 3 - 未找到错误
【发布时间】:2018-11-07 23:01:47
【问题描述】:

我正在尝试在 ASP.NET Core 网站中使用新的 EntityFrameworkCore.Cosmos Preview 3 包,但在尝试创建数据库时不断收到错误消息。我似乎找不到任何文档来让我了解导致错误的原因。

在我的 Startup.cs 文件的 ConfigureServices 方法中,我有以下代码:

// Configure EntityFramework - CosmosDB
services.AddDbContext<EFContext>(options => options.UseCosmos(
    authKeyOrResourceToken: ServiceFactory.GetDbKeySecret(_config, (_hosting.EnvironmentName != "LocalDev")),
    serviceEndPoint: _config.GetValue<string>("CosmosDb:Endpoint"),
    databaseName: _config.GetValue<string>("CosmosDb:DatabaseID")
));
EFContext efc = services.BuildServiceProvider().GetRequiredService<EFContext>();
efc.Database.EnsureCreatedAsync().Wait();

当它到达最后一行时,我收到以下错误(堆栈跟踪):

at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClient.CreateDatabaseIfNotExistsOnceAsync(DbContext _, Object __, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken)

而使用 Fiddler 的详细响应是:“{”code”:“NotFound”,“message”:“系统中不存在具有指定 id 的实体。\r\nActivityId: 6aed2df0-abe8-4e93-b468 -b3188005fcb5, Microsoft.Azure.Documents.Common/2.1.0.0"}"

我已经检查并仔细检查了我的配置中的所有值是否正确并且与我在 Azure 中的 CosmosDB 帐户相匹配,但我仍然无法找出导致此错误的原因。

有没有人遇到过这个问题并有解决方案? 谢谢

【问题讨论】:

  • 您确定在尝试创建数据库时会发生这种情况吗?该错误消息似乎表明具有指定 id 的文档不存在。
  • 绝对是在创建数据库期间,或者更准确地说是在检查数据库是否存在期间(显然)。无论数据库是否存在,我都会收到相同的消息(我在没有数据库的情况下尝试过,然后在门户中创建了一个同名的数据库,然后再次尝试得到相同的结果)。目前还没有涉及文档。

标签: asp.net-core entity-framework-core azure-cosmosdb


【解决方案1】:

我发现之前发布的一个类似问题 (Azure Cosmos DB - CreateDatabaseAsync - Resource Not Found) 有人遇到了相同类型的问题,并通过删除数据库并重新创建来解决它。我尝试了同样的事情,发现我的代码按预期工作。

我猜在创建原始 CosmosDB 帐户时从未报告过一些错误(或者我错过了某处的错误消息)。因此,如果有人收到类似消息,请尝试重新创建您的帐户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-29
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 2022-10-18
    相关资源
    最近更新 更多