I am trying to use the new EntityFrameworkCore.Cosmos Preview 3 package in an ASP.NET Core website, but I keep getting an error back when trying to Create the DB. I can't seem to find any documentation to give me an idea of what is causing the error.
In my Startup.cs file in the ConfigureServices method I have the following code:
// 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();
When it gets to the last line I get the below error (stack trace):
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)
And with Fiddler the detailed response is: "{"code":"NotFound","message":"Entity with the specified id does not exist in the system.\r\nActivityId: 6aed2df0-abe8-4e93-b468-b3188005fcb5, Microsoft.Azure.Documents.Common/2.1.0.0"}"
I have checked and double checked all the values in my config are correct and match to my CosmosDB account in Azure, but I still can't figure out what is causing this error.
Has anyone run into this and have a solution? Thanks