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; orIOrganization.Execute()
and create an update requestAnd if the answer is 'it depends', what situation warrants which method?
Thanks
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
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