首页 > 解决方案 > 将 CosmosDB 提供程序用于 Entity Framework Core 和 Azure 表时出错

问题描述

我正在尝试使用 EF Core 和 Azure Table(来自 Azure 存储帐户)做一个简单的 CRUD 应用程序。

我将存储帐户的名称作为数据库名称传递(文档对此并不完全清楚)

services.AddDbContext<HomioDbContext>(options =>    
                options.UseCosmos(
                    "https://homiostorage.table.core.windows.net/",
                    "{Account Key}",
                    databaseName: "{name of storage account}"));

执行任何 db 操作都会引发以下错误(HTTP 标头之一的值格式不正确

CosmosException;StatusCode=BadRequest;SubStatusCode=0;ActivityId=00000000-0000-0000-0000-000000000000;RequestCharge=0;Message=Response status code does not indicate success: 400 Substatus: 0 Reason: (<?xml version="1.0" encoding="utf-8" standalone="yes"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">  <code>InvalidHeaderValue</code>  <message xml:lang="en-US">The value for one of the HTTP headers is not in the correct format.RequestId:cdef27c9-3002-0084-60dd-d9b8b0000000Time:2020-02-02T15:29:31.9748413Z</message></error>, Request URI: /, RequestStats: , SDK: Windows/10.0.18363 cosmos-netstandard-sdk/3.3.0).;Diagnostics

已经坚持了一段时间......真的可以使用一些帮助!

标签: c#azure.net-coreentity-framework-coreazure-cosmosdb

解决方案


根据文档here,用于 Cosmos DB 的 EF Core Provider 仅支持 SQL API(至少在撰写此答案时),并且您正在将它用于表存储。这就是您收到此错误的原因。


推荐阅读