Stop CRM Query From Being Cached RRS feed

  • Question

  • We've built some REST based Web Services using Microsoft's WebAPI platform that will integrate with CRM2011 and an external system.

    One of our Web Services contains a select against a custom entity (named AccountRecs) that is linked off of the Contact entity.  The query retrieves all the related records for a Contact, loops through them, and sums a decimal field on each record.  This approach was taken as we decided to use Linq querying syntax rather than FetchXML.  Here is what the code looks like:

    using (XrmServiceContext xrm = new XrmServiceContext("Xrm"))
    decimal runningSum = 0;

    var recs = (from a in xrm.new_accountrecsSet
                    where a.new_accountid.Id == AccountID
                    select new new_accountrecs
                        new_amount = a.new_amount
    foreach (var r in recs)
        if (r.new_amount != null)
            runningSum = runningSum + (decimal)r.new_amount;

    The issue we are having is that if someone goes into CRM and modifies the new_amount field on one of these records, we are not getting the updated amount in our query.  Instead, we are seeing the same sum amount from before the update.

    The only way we can force the web service to get the correct value is to restart Visual Studio during testing or restart the Website when it's been published. 

    I've written plugins/custom workflows for years and I've never had to deal with a caching issue like this. Any ideas where this is occurring and how we can resolve it?

    Tuesday, April 19, 2016 7:44 PM

All replies