ADringer
ADringer

Reputation: 2834

IOrganizationService correct way to update entities

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:

Thanks

Upvotes: 1

Views: 1760

Answers (2)

Henk van Boeijen
Henk van Boeijen

Reputation: 7948

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.

Upvotes: 1

Guido Preite
Guido Preite

Reputation: 15138

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

Upvotes: 4

Related Questions