Azure Table Storage SDK-无法插入 [英] Azure Table Storage SDK - Can't Insert

查看:57
本文介绍了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="http://schemas.microsoft.com/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-无法插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆