简体   繁体   English

带有现有CosmosDB 404错误的实体框架核心

[英]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.

相关问题 将 CosmosDB 提供程序用于 Entity Framework Core 和 Azure 表时出错 - Error while using CosmosDB provider for Entity Framework Core with Azure Tables 带有 Azure CosmosDB 的 Entity Framework Core 被重复初始化 - Entity Framework Core with Azure CosmosDB is repeatedly initialised 将 Microsoft Graph 添加到现有的 Entity Framework Core - Adding Microsoft Graph to existing Entity Framework Core 映射到 CosmosDB 集合时,有什么方法可以将默认值设置为 Entity Framework Core 实体的属性 - Is there any way to set default value to a property of Entity Framework Core entity when mapping to CosmosDB collection 在 Entity Framework Core 中出错 - Getting an error in Entity Framework Core 为什么 Entity Framework Core 2.2 C# 在插入具有现有嵌套实体的新实体时响应错误 - Why does Entity Framework Core 2.2 C# respond with an error while inserting a new entity with an existing nested entity Entity Framework Core - 从现有数据库创建模型后尝试添加迁移时出错 - Entity Framework Core - Error when trying to Add Migration after creating Model from existing database Entity Framework Core 5 和 CosmosDB SQL API - 包含扩展方法不起作用 - Entity Framework Core 5 and CosmosDB SQL API - Include extension method does not work 如何使用 Entity Framework Core 将现有存储过程添加到 dbcontext - How to add an existing stored procedure to dbcontext with Entity Framework Core 实体框架核心使用预先存在的ID密钥 - Entity Framework Core Use Pre-Existing ID Key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM