Alex Gordon
Alex Gordon

Reputation: 60751

Requesting the most recent version of an entity in CRM

I'm updating an entity using the Organization Service:

    _organizationService.Update(contact);

I then would like to immediately query CRM for the latest version of that record by issuing something like:

_xrmServiceContext.ContactSet.FirstOrDefault(x => x.Id == contactGuid);

I'm noticing that the _xrmServiceContext is returning old data, unless I do a Thread.Sleep(1000) before requesting the updated data.

Is there a way to "wait" until the data is updated?

I'm looking at this as a possible solution; however, I am not sure how I would change my implementation to match this pattern.

Upvotes: 2

Views: 53

Answers (1)

dynamicallyCRM
dynamicallyCRM

Reputation: 2980

XrmServiceContext takes in organization service as a parameter which is cached.

Use clear changes _xrmServiceContext.ClearChanges();

Or alternatively you could new up another XrmServiceContext object by passing a newed up organizationservice.

var uncachedOrganizationService = new OrganizationService("Xrm");
var uncachedXrmServiceContext = new XrmServiceContext(uncachedOrganizationService);
uncachedXrmServiceContext.ContactSet.FirstOrDefault(x => x.Id == contactGuid);

Upvotes: 2

Related Questions