我真的为此挠头。我正在尝试使用 Dynamics CRM SDK 来更新客户记录。无论我尝试什么,它都失败了。开始。
Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>();
sampleAccount.Name = "AMC Edited";
crmService.Update(sampleAccount);
给出错误:EntityState 必须设置为 null、Created(对于 Create 消息)或 Changed(对于 Update 消息)
XrmServiceContext ctx = new XrmServiceContext(crmService);
Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>();
sampleAccount.Name = "AMC Edited";
ctx.UpdateObject(sampleAccount);
ctx.SaveChanges();
给出错误:上下文当前未跟踪“帐户”实体。
XrmServiceContext ctx = new XrmServiceContext(crmService);
Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>();
sampleAccount.Name = "AMC Edited";
ctx.Attach(sampleAccount);
ctx.UpdateObject(sampleAccount);
ctx.SaveChanges();
给出错误:“帐户”实体已附加到上下文。
作为参考, 1. Account 对象由 SDK 早期绑定代码生成工具创建 2. crmService 是 IOrganizationService 连接对象 3. GetAccounts ... 执行 LINQ 查询并返回 IEnumerable
请帮忙。谢谢,克里斯。