我试过应用在网上找到的几个建议,但在用linq查询CRM 2011时仍然遇到缓存结果。我的web.config文件内容如下,这是应该禁用结果缓存:如何防止CRM 2011 SDK中的查询缓存?
<configSections>
<section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
</configSections>
<connectionStrings>
...
<connectionStrings>
<microsoft.xrm.client>
<contexts>
<add name="Xrm" type="Xrm.XrmServiceContext, Xrm" serviceName="Xrm"/>
</contexts>
<services>
<add name="Xrm" type="Microsoft.Xrm.Client.Services.OrganizationService, Microsoft.Xrm.Client"/>
</services>
</microsoft.xrm.client>
在代码中,我有一个小测试循环等待外部变化的一些数据:
Dim crm As New XrmServiceContext("Xrm")
Dim oOpptyGuid = ' <an existing GUID in the system>
' Get opportunity by guid.
Dim oOppty As Xrm.Opportunity = (From c In crm.OpportunitySet Where c.Id.Equals(oOpptyGuid) Select c).SingleOrDefault
Dim sName As String = oOppty.Name
Dim iTries As Int16 = 0
' Wait till name is changed or tried too many times.
Do
' Sleep between tries.
Threading.Thread.Sleep(10000)
iTries += 1
' Get opportunity by guid.
oOppty = (From c In crm.OpportunitySet Where c.Id.Equals(oOpptyGuid) Select c).SingleOrDefault
Loop Until oOppty.Name <> sName Or iTries > 10
的上面的循环从未检测到名称在CRM中的其他位置发生更改。我试着从缓存中手动删除的项目,在循环查询之前,但没有喜悦:
oCacheManager = Microsoft.Xrm.Client.Caching.ObjectCacheManager.GetInstance()
For Each x As String In From y In oCacheManager Select y.Key
oCacheManager.Remove(x)
Next
的只的事情,对我的工作原理是这样的:
crm.Dispose()
crm = New XrmServiceContext("Xrm")
我可以忍受这一点,但它会更好,而不是重新创建上下文,以确保在代码或web.config中无缓存。但是我无法找到适合我的解决方案。我错过了什么吗?
谢谢,这工作!不知道是谁回答 - 我认为,从阅读保罗的答复中,你首先采用了这种方法。 :) – 2012-03-23 17:01:24