I really scratch my head with this. I am trying to use the Dynamics CRM SDK to update an account entry. No matter what I try, this fails. Here it goes.
Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>(); sampleAccount.Name = "AMC Edited"; crmService.Update(sampleAccount);
Gives an error: EntityState must be set to null, Created (to create a message) or Modified (for a Refresh message)
XrmServiceContext ctx = new XrmServiceContext(crmService); Account sampleAccount = CrmAccount.GetAccountsBySubmissionCode(crmService, "ERZZUP").Single<Account>(); sampleAccount.Name = "AMC Edited"; ctx.UpdateObject(sampleAccount); ctx.SaveChanges();
Gives an error: the context does not currently track the "account" object.
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();
Gives an error: the "account" object is already bound to the context.
For reference, 1. An Account object is created using the SDK early code generation tool 2. crmService is an IOrganizationService 3 connection object. GetAccounts ... executes a LINQ query and returns IEnumerable
Please, help. Thanks, Chris.
source share