1

CRM 2011 で LINQ を使用してレコードを検索し、見つかったレコードを更新する際に問題が発生しています。この非常に単純なバージョンでさえ機能しません。エラーは完全に一般的です (以下を参照)。

これがコードです。クエリからエンティティを取得しますが、更新できません。

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 に答える