I faced this issue recently. The exact replication steps would be to initialize a CRM Service Context and use it to retrieve the same (set of) record(s) more than once, with first query retrieving a set of attributes and second query retrieving some other set of attributes. In this scenario, you would notice that the second query returns NULL values for almost all the attributes.
The reason for this behavior that CRM Service Context caches the results once retrieved. So when the first query returned a set of attributes, it cached the record with only those values. When the second query is executed, the query is not run on the DB at all, but on the cached data. Since the second query has a different set of attributes, it returns NULL values.
How to workaround this issue:
There are two options.
1. Re-create the service context everytime a query is executed. This makes the ServiceContext fetch the data from CRM everytime.
2. Or you could call the ClearChanges() method in the Service context. But just take care, that you don't clear the CRUD changes.
No comments:
Post a Comment