我試過應用在網上找到的幾個建議,但在用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