如何获取Windows Azure表插入的最新ID

时间:2013-05-17 14:14:08

标签: azure azure-table-storage

是否可以通过windows azure获取插入表格的最新ID?

我的代码如下:

private IMobileServiceTable<FooToo> MyTable = App.MobileService.GetTable<FooToo>();

Foo new = new Foo(); 
await MyTable.InsertAsync(new);

InsertAsync之后我需要插入的元素的ID。怎么做?

1 个答案:

答案 0 :(得分:2)

在您的情况下,new项将包含在InsertAsync行之后在服务器上获得的Id。

我使用的工作示例

//Creates an empty item (id is now null)
MyClass newItem = new MyClass();

//Uploading the item
await MobileService.GetTable<MyClass>().InsertAsync(newItem);

//Returning the id which is now the Id of the row on the server
return newItem.Id;