Azure表存储只支持作为数据types的string?

我试图插入数据到一个Azure表,但一切都转换为string。

例如,我插入数字/布尔值

var test={ PartitionKey : '4', RowKey : '2', foo: 4, bar: true }; tableService.insertEntity('mytable', test, ...); 

 tableService.queryEntity('mytable', '4', '2', ...); 

回报

 { id: 'http://127.0.0.1:10002/devstoreaccount1/identid(PartitionKey=\'4\',RowKey=\'2\')', link: 'identid(PartitionKey=\'4\',RowKey=\'2\')', updated: '2012-12-12T10:26:44Z', etag: 'W/"datetime\'2012-12-12T10%3A26%3A44.547Z\'"', PartitionKey: '4', RowKey: '2', Timestamp: '2012-12-12T10:20:44.897Z', foo: '4', bar: 'true' } 

我怎样才能指定一个数据types?


好的,刚刚在SDK中看到,您可以指定数据types

 var test={ PartitionKey : '4', RowKey : '2', foo: { '@': { type: 'Edm.Int32' }, '#': 4 } }; 

但是有没有帮助函数自动添加types?

由于SDK似乎没有包含任何有用的东西,所以我现在写这些东西:

 function azType(type, v) { return { "@": { type: type }, "#": v }; } function azBool(v) { return azType("Edm.Boolean", v); } function azBinary(v) { return azType("Edm.Binary", v); } function azByte(v) { return azType("Edm.Byte", v); } function azDateTime(v) { return azType("Edm.DateTime", v); } function azDateTimeOffset(v) { return azType("Edm.DateTimeOffset", v); } function azDecimal(v) { return azType("Edm.Decimal", v); } function azDouble(v) { return azType("Edm.Double", v); } function azGuid(v) { return azType("Edm.Guid", v); } function azInt64(v) { return azType("Edm.Int64", v); } function azInt32(v) { return azType("Edm.Int32", v); } function azInt16(v) { return azType("Edm.Int16", v); } function azSByte(v) { return azType("Edm.SByte", v); } function azSingle(v) { return azType("Edm.Single", v); } function azString(v) { return azType("Edm.String", v); } function azTime(v) { return azType("Edm.Time", v); } 

如在

 var test={ PartitionKey : '4', RowKey : '2', foo: azInt32(4) }; 

我不知道他们为什么改变它,但是从0.6.10开始,azType函数需要被replace:

 function azType(type, v) { return { "$": { type: type }, "_": v }; } 

表服务数据模型只支持这8种types:

  • Edm.Binary
  • Edm.Boolean
  • Edm.DateTime
  • Edm.Double
  • Edm.Guid
  • Edm.Int32
  • Edm.Int64
  • Edm.String

通过http://msdn.microsoft.com/en-us/library/windowsazure/dd179338.aspx

并小心你的对象的id属性:

{ PartitionKey : '4', RowKey : '2', id: azInt32(4) };

如果你试图这样做,错误信息并不那么明显:

Error inserting : { [Error: [object Object]] code: 'PropertiesNeedValue', message:{ _: 'The values are not specified for all properties in the entity...','$': { 'xml:lang': 'en-US' } } }

    Interesting Posts