【问题标题】:Does the EF Core Cosmos DB provider support the new Bulk API for Cosmos DB?EF Core Cosmos DB 提供程序是否支持 Cosmos DB 的新批量 API?
【发布时间】:2020-08-13 19:44:33
【问题描述】:

我们使用的是最新的 EF Core 3.1 和 Cosmos DB 提供程序。我们希望对 Cosmos DB 进行批量插入,但不知道最新的 EF Core 提供程序是否支持 Cosmos DB 的新批量 API。

EF Core Cosmos DB 提供程序是否支持 Cosmos DB 的新批量 API?

我们查看了https://github.com/dotnet/efcore,但无法确定它是否受支持。我们还查看了https://docs.microsoft.com/en-us/ef/core/providers/cosmos/

【问题讨论】:

    标签: azure-cosmosdb ef-core-3.1


    【解决方案1】:

    它不包括本机 Cosmos .NET sdk v3 中的批量支持。您必须使用本机 .NET SDK v3 来执行批量操作。我们有一个从 4 月开始的 blog post,其中包含更多详细信息。

    【讨论】:

      【解决方案2】:

      实体框架没有隐式提供,但您可以从 DBContext 类获取 cosmos 客户端并显式执行。

      这是一个例子:

              CosmosClient cosmosClient = _context.Database.GetCosmosClient();
              Database database = cosmosClient.GetDatabase("PersonalizationOrder");
              Container container = database.GetContainer(typeof(T).Name);
              var data = await container.CreateItemAsync(new Order
              {
                  Id = Guid.NewGuid(),
                  PartitionKey = "1",
                  ShippingAddress = new StreetAddress()
                  {
                      City = "XYZ",
                      Street = "Street, ttt st"
                  }
              });
      

      【讨论】:

        猜你喜欢
        • 2021-03-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-10
        • 1970-01-01
        • 2019-10-08
        • 1970-01-01
        相关资源
        最近更新 更多