IOrganizationService correct way to update entities

落爺英雄遲暮 提交于 2019-12-10 11:39:51

问题


I'm having a look at the best way of updating/retrieve entities from within C#. I've had a read through the MSDN documentation but unsure which way to go/when to use either method.

So, my question:

Should I be using:

  • IOrganizationService.Update() and update the entity directly; or
  • IOrganization.Execute() and create an update request

    And if the answer is 'it depends', what situation warrants which method?

Thanks


回答1:


First of all both Update and Execute of an UpdateRequest produce the same result.

The main difference is that an UpdateRequest can be batched using the ExecuteMultipleRequest




回答2:


With the CreateRequest as well as the UpdateRequest you can switch duplicate detection, as in the following example:

public Guid CreateTest(Entity account, IOrganizationService service)
{
    var request = new CreateRequest { Target = account };
    request.Parameters.Add("SuppressDuplicateDetection", false);
    var response = service.Execute(request) as CreateResponse;
    return response.id;
}

You cannot do this using the Create and Update methods.

And, of course, you can feed Request objects to the ExecuteMultipleRequest to throttle the number of roundtrips to the OrganizationService.

I expect the Create and Update methods to be slightly more efficient, but I doubt if it would be measurable.



来源:https://stackoverflow.com/questions/28245690/iorganizationservice-correct-way-to-update-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!