Azure 表存储 sdk 1.6 Upsert 未插入
我正在尝试使用 asure sdk 1.6 的新 upsert 功能(针对存储模拟器)。
但我只是设法让更新工作。当我尝试更新插入新的行键时,出现资源未找到
异常。
var context = new TableServiceContext(_cloudStorageAccount.TableEndpoint.ToString(), _cloudStorageAccount.Credentials)
{
MergeOption = MergeOption.NoTracking,
ResolveType = (unused) => typeof(SmartTableServiceEntity)
};
context.AttachTo(tableName, smartEntity, "*");
context.UpdateObject(smartEntity);
context.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate);
如果我放置 AddObject
它会执行插入但不会更新。 我想借助新的 sdk,能够一次完成这两项任务。
I'm trying to use the new upsert feature of asure sdk 1.6 (against the storage emulator).
But I only managed to get the update working. When I try to upsert whit a new rowkey I get resource not found
exception.
var context = new TableServiceContext(_cloudStorageAccount.TableEndpoint.ToString(), _cloudStorageAccount.Credentials)
{
MergeOption = MergeOption.NoTracking,
ResolveType = (unused) => typeof(SmartTableServiceEntity)
};
context.AttachTo(tableName, smartEntity, "*");
context.UpdateObject(smartEntity);
context.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate);
If I put AddObject
it does the insert but not the update.
I was thinking being able to do both in one action thanks to the new sdk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它仅适用于真正的 Azure 存储。开发存储不支持Upsert操作。
此外,您还必须将 tableServiceContext 的 IgnoreResourceNotFoundException 属性设置为 true。
it will only work against real Azure storage. Development storage does not support Upsert operation.
Also you must set the IgnoreResourceNotFoundException property of the tableServiceContext to true.
我想出了一个似乎适用于 devstorage 和真实存储的解决方案,
有人有更好的解决方案吗?
请注意“*”和 null 之间的区别,可以吗?
提前谢谢你
I came up this a solution that seems to works on devstorage and on real storage
does someone has a better solution?
notice the difference bettween "*" and null is it ok?
thank you by advance
使用真实的 Azure 帐户以及将 IgnoreResourceNotFoundException 设置为 true 时,为 eTag 参数传递 null 或使用不接受 eTag 值的重载也很重要。否则你会得到 ResourceNotFound 异常。
When using the real Azure accounts, as well as setting the IgnoreResourceNotFoundException to true, it is also important to pass null for the eTag parameter, or use the overload that does not accept the eTag value. Otherwise you will get ResourceNotFound exceptions.