Azure Table Storage SDK

编程入门 行业动态 更新时间:2024-10-27 18:30:28
本文介绍了Azure Table Storage SDK-无法插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 Azure Table Storage SDK 和我可以很好地读取和删除实体,但是插入操作为我提供了以下XmlException.有什么想法吗?

I am working with Azure Table Storage SDK and I can read and delete entities fine but insert operations give me the following XmlException. Any ideas?

An exception of type 'System.Xml.XmlException' occurred in System.Xml.dll but was not handled in user code Additional information: Data at the root level is invalid. Line 1, position 1.

这是我的插入代码:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=myKey"); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("positions"); await table.CreateIfNotExistsAsync(); var p = new PositionEntity("test", Guid.NewGuid().ToString()); TableOperation insertOperation = TableOperation.Insert(p); var result = table.ExecuteAsync(insertOperation).ContinueWith(t => { if (t.Exception != null) { // read Exception here... var x = RequestResult.TranslateFromExceptionMessage(t.Exception.Message); } });

注意:我正在DNX 4.5.1.上运行.

Note: I am running on DNX 4.5.1.

事实证明,我的 PositionEntity 具有未设置的DateTimeOffset属性.它不可为空,因此使用默认的DateTimeOffset值实例化.如果我在发送之前手动设置了Date属性,则插入可以正常工作.

It turns out that my PositionEntity has a DateTimeOffset property that was not being set. It was not nullable and therefore was being instantiated with the default DateTimeOffset value. If I set the Date property manually before sending, the insert works properly.

var p = new PositionEntity("test", Guid.NewGuid().ToString()); p.Date = DateTime.Now; // <-- This is required if default. Default value doesn't work!

这是Azure的原始响应:

Here is the raw response from Azure:

<?xml version="1.0" encoding="utf-8"?><error xmlns="schemas.microsoft/ado/2007/08/dataservices/metadata"><code>OutOfRangeInput</code><message xml:lang="en-US">One of the request inputs is out of range. RequestId:eeb6ed0c-0002-001f-48f5-f64ea4000000 Time:2015-09-24T18:18:32.8854764Z</message></error>

有人知道为什么默认的DateTimeOffset值({01/01/0001 12:00:00 AM +00:00})在Azure Table Storage中不是有效值吗?!

Does anyone know why the default DateTimeOffset value ({01/01/0001 12:00:00 AM +00:00}) is not a valid value in Azure Table Storage?!?

推荐答案

列出支持的DateTime范围从UTC公元1601年1月1日午夜12:00开始.范围结束于9999年12月31日.

Turns out the supported DateTime range begins from 12:00 midnight, January 1, 1601 A.D., UTC. The range ends at December 31, 9999.

仅供参考: MSDN 提供了下表,其中详细介绍了Azure表存储中数据类型的数据范围:

FYI: MSDN has provided the following table detailing the data ranges of the data types in Azure Table Storage:

更多推荐

Azure Table Storage SDK

本文发布于:2023-08-01 16:34:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269891.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Table   Azure   SDK   Storage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!