Dynamics CRM保存实体更改-获取错误 [英] Dynamics CRM saving Entity Changes - Getting Errors

查看:93
本文介绍了Dynamics CRM保存实体更改-获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的为此感到挠头。我正在尝试使用Dynamics CRM SDK更新帐户记录。无论我尝试什么,都失败了。

I'm really scratching my head with this. I'm trying to use the Dynamics CRM SDK to update an account record. No matter what I try, it's failing. Here goes.

Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>();
sampleAccount.Name = "AMC Edited";
crmService.Update(sampleAccount);

给出错误: EntityState必须设置为null,Created(用于Create message)或已更改(用于更新消息)

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

For reference, 1. The Account object is created by the SDK Early Bound Code Generation Tool 2. crmService is the IOrganizationService connection object 3. GetAccounts ... performs a LINQ query and return an IEnumerable

请帮助。
克里斯,
克里斯。

Please help. Thanks, Chris.

推荐答案

请参阅 http://msdn.microsoft.com/en-us/library/gg695783.aspx ,尤其是多个数据上下文 部分。您似乎在使用多个上下文来跟踪实体。 CrmAccount.GetAccountsBySubmissionCode 方法只会对您隐藏。

Refer to http://msdn.microsoft.com/en-us/library/gg695783.aspx, particularly the "Multiple Data Contexts" part. It seems you're using multiple contexts to track the entities. The CrmAccount.GetAccountsBySubmissionCode method just hides this from you.

请确保在 CrmAccount中.GetAccountsBySubmissionCode 方法来处理上下文/服务,然后返回 IEnumerable< Account> ,或确保对更新

Make sure within the CrmAccount.GetAccountsBySubmissionCode method to dispose of the context/service before returning the IEnumerable<Account>, or make sure you use the same context/service to Update.

这篇关于Dynamics CRM保存实体更改-获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆