1

我在使用 LINQ 查找记录然后更新找到的记录时遇到问题 CRM 2011。即使是这个超级简单的版本也行不通。错误是完全通用的(见下文)。

这是代码,我确实从查询中返回了一个实体,但我无法更新它。

var account = orgContext.CreateQuery("account").First(c => c["name"] == "apple");

account["name"] = "Microsoft";

orgContext.UpdateObject(account);
orgContext.SaveChanges();  ///ERROR HERE




ERROR DETAIL

Microsoft.Xrm.Sdk.SaveChangesException was unhandled by user code
  Message=An error occured while processing this request.
  Source=Microsoft.Xrm.Sdk
  StackTrace:
       at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions options)
       at Dhs.Tsa.Trip.Xrm.Plugins.ProcessNFL.Execute(IServiceProvider serviceProvider) in C:\Users\Administrator\Desktop\Dhs.Tsa.Trip.Xrm\Dhs.Tsa.Trip.Xrm.Plugins\ProcessNFL.cs:line 54
       at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
  InnerException: System.ServiceModel.FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>
       Message=System.InvalidOperationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #97345966
       Source=Microsoft.Crm.Extensibility
       StackTrace:
            at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)
            at Microsoft.Crm.Extensibility.InprocessServiceProxy.ExecuteCore(OrganizationRequest request)
            at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request)
            at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChange(OrganizationRequest request, IList`1 results)
       InnerException: 
4

1 回答 1

1

我不是 100% 确定该错误指的是什么,但我知道过去我在尝试使用与检索到的相同对象进行更新时遇到了问题。例如,如果您获取的对象缺少必填字段,它可能不喜欢您再次尝试将其保存回来。

无论如何,解决方案很简单。而不是...

account["name"] = "Microsoft";

orgContext.UpdateObject(account);
orgContext.SaveChanges();

尝试做...

var updAccount = new Entity("account") { Id = account.Id };
updAccount["name"] = "Microsoft";

orgContext.UpdateObject(updAccount);
orgContext.SaveChanges();

这有效地创建了帐户参考的副本,其中仅包含您要更新的字段。

于 2012-08-10T14:29:19.393 回答