Answered by:
How to dispose context after query CRM 4 plugin

Question
-
Hello,
I have a query like this:
int? priorityIsUsed = (from wrs in crm.workrequests where wrs.statuscode == PreWRstatus && wrs.daa_priority == wrPriority select wrs.daa_priority).Count();
It's working two times after a iisreset, so I think the problem should be in the crm context created.
var crm = new Xrm.XrmDataContext("Default", context, true);
I've tried with this before the query, but working also two times only:
crm.UsingService(service => {
I had a query like this before change it:
var priorityIsUsed = (from wrs in crm.workrequests where wrs.statuscode == PreWRstatus && wrs.daa_priority == wrPriority select wrs.daa_priority).FirstOrDefault();
How could I do this query correctly?
- Edited by RDevelopment Monday, April 28, 2014 10:57 AM
Monday, April 28, 2014 10:27 AM
Answers
-
Ok..try to to this
Configure to disable cache : http://msdn.microsoft.com/en-us/library/gg398020.aspx
After
var crm = new Xrm.XrmDataContext("CacheDisabled"); crm.UsingService(service => { }
Alessandro Graps
- Proposed as answer by [MVP] Alessandro Graps Monday, April 28, 2014 4:19 PM
- Marked as answer by RDevelopment Tuesday, April 29, 2014 8:26 AM
Monday, April 28, 2014 4:19 PM
All replies
-
Hi,
Do you have an error?
Bye
AlessandroAlessandro Graps
Monday, April 28, 2014 2:44 PM -
Not an error.
In this case, when I run the query
var priorityIsUsed = (from wrs in crm.workrequests where wrs.statuscode == PreWRstatus && wrs.daa_priority == wrPriority select wrs.daa_priority).FirstOrDefault();
It doesn't give me any result (priorityIsUsed is null)
and for sure there are records that match the criteria.
Monday, April 28, 2014 2:56 PM -
Ok..try to to this
Configure to disable cache : http://msdn.microsoft.com/en-us/library/gg398020.aspx
After
var crm = new Xrm.XrmDataContext("CacheDisabled"); crm.UsingService(service => { }
Alessandro Graps
- Proposed as answer by [MVP] Alessandro Graps Monday, April 28, 2014 4:19 PM
- Marked as answer by RDevelopment Tuesday, April 29, 2014 8:26 AM
Monday, April 28, 2014 4:19 PM -
Thanks for you reply.
I finally did what was explained in this thread, about CRM 4 sdk disable caching
public static void ClearCache(string entityName) { const string format = "adxdependency:crm:entity:{0}"; var dependency = string.Format(format, entityName).ToLower(); var cache = Microsoft.Xrm.Client.Caching.CacheManager.GetBaseCache(); cache.Remove(dependency); }
Tuesday, April 29, 2014 8:28 AM