[英]Entity Framework Core with Existing CosmosDB 404 error
public class dbcontext:DbContext
{
public DbSet<entity1> entities1 { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseCosmos(
"https://localhost:8081",
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
"myDocuments");
}
public class entity1
{
[Key]
public string id { get; set; }
public string name { get; set; }
}
}
Below error when trying to create a document.. using Microsoft.EntityFrameworkCore.Cosmos Preview3 and cosmos emulator 使用Microsoft.EntityFrameworkCore.Cosmos Preview3和cosmos模拟器尝试创建文档时出现以下错误
I think the reason for this is the preview nature of the Cosmos DB provider. 我认为这样做的原因是Cosmos DB提供程序的预览性质。 I was having the same issue.
我有同样的问题。 I'd pre-created my collection using the storage emulator which requires you to define a partition key.
我使用存储仿真器预先创建了我的收藏集,这需要您定义一个分区键。 Note that there is no notion of a "partition key" with the preview Cosmos provider.
请注意,预览Cosmos提供程序没有“分区键”的概念。 That's a huge problem for Cosmos DB.
对于Cosmos DB来说,这是一个巨大的问题。 However the emulator appears to be fairly resilient.
但是,仿真器似乎具有相当的弹性。
If you do as Nick Chapsas suggests and make a call to context.Database.EnsureCreated you should see a new collection has been created in the emulator. 如果您按照Nick Chapsas的建议进行操作,并调用context.Database.EnsureCreated,则应该看到已在模拟器中创建了一个新集合。 If you look at the new collection's Scale & Settings you'll find no partition key.
如果您查看新集合的“比例和设置”,将找不到分区键。 Partition key is a required field when creating a new collection.
创建新集合时,分区键是必填字段。 The preview provider appears to be creating collections that are not valid.
预览提供程序似乎正在创建无效的集合。 The emulator seems to be OK with that but Azure Cosmos DB is not.
模拟器似乎可以,但Azure Cosmos DB则不能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.