c# - 将 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
已经坚持了一段时间......真的可以使用一些帮助!
解决方案
根据文档here
,用于 Cosmos DB 的 EF Core Provider 仅支持 SQL API(至少在撰写此答案时),并且您正在将它用于表存储。这就是您收到此错误的原因。
推荐阅读
- sql - 灵活的结果表,列基于另一个表的行
- asp.net - 如何使页面接受 asp.net 中的 mimetype
- java - DTO、DAO 和实体?需要实体吗?这3个的最佳实践?
- java - Java - 使用三个线程处理文件
- asp.net-core - IIS Rest Api - 放置和删除请求不起作用 ERR_FAILED 403
- go - 如果标准 golang big.Int 函数接受两个参数并返回一个值,为什么它会使用接收器?
- node.js - 减少返回空数组
- python-3.x - 将单纯形从 Delaunay 三角剖分转换为 networkx 图
- node.js - 在电报中通过我的帐户发送消息
- java - 在 kotlin 中添加到地图时出现 UnsupportedOperationException