无法保存 Nullable当 Azure 表为空时
例如,我有一个 bool? C#中的Status
当Status = true/false
时,它可以保存到Azure表,没问题
但是当Stats = null
时,它无法保存(更新)到Azure表,该列仍然保留旧值
我想这可能是因为Azure表没有方案,但是解决方案是什么?
如何保存null来覆盖原始值?
编辑,代码
数据如下:
public class someEntity : TableServiceEntity
{
public bool? Status { get; set; }
}
更新如下:(
tableContext.AttachTo("sometable", someEntity);
tableContext.UpdateObject(someEntity);
tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch & SaveChangesOptions.ReplaceOnUpdate);
我尝试将 AttachTo
与 "*"
作为 etag,尝试删除 SaveChangesOptions
,都不起作用)
对不起我的愚蠢,应该是这段代码,然后就可以了
tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch | SaveChangesOptions.ReplaceOnUpdate);
For example, I have a bool? Status
in c#
when the Status = true/false
, it can save to Azure table, no problem
But when Stats = null
, it cannot save(update) to Azure table, the column still keeps the old value
I guess it might because Azure table does not have a scheme, but whats the solution?
How to save a null to overwrite the original value?
EDIT, the code
data like this:
public class someEntity : TableServiceEntity
{
public bool? Status { get; set; }
}
update like this:
tableContext.AttachTo("sometable", someEntity);
tableContext.UpdateObject(someEntity);
tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch & SaveChangesOptions.ReplaceOnUpdate);
(I tried AttachTo
with "*"
as etag, tried remove SaveChangesOptions
, neither work)
SORRY for my stupid, should be this code, then works
tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch | SaveChangesOptions.ReplaceOnUpdate);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@Matthew建议的,我把答案放在这里
非常简单,使用:
对于多个选项,使用
| (或)
,而不是& (和)
。 原因SaveChangesOptions.ReplaceOnUpdate = true
表示整个实体将被替换SaveChangesOptions.ReplaceOnUpdate = false
,表示合并,旧数据将保留As @Matthew suggested, I put the answer here
very simple, use:
For multiple options, use
| (or)
, not& (and)
. ReasonSaveChangesOptions.ReplaceOnUpdate = true
means the whole entity will be replacedSaveChangesOptions.ReplaceOnUpdate = false
, means merge, the old data will be kept