2011-12-08 19 views
2

Windowsサービス内でCrmOrganizationServiceContextRetrieveMultipleオペレーションに対してFetchExpressionを使用して、キューからアイテムをフェッチして処理しています。FetchExpressionの結果がキャッシュされているように見えますが、どうすればこの問題を防ぐことができますか?

初めて実行すると、正しく処理されるアイテムが取得されます。同一のCrmOrganizationServiceContextインスタンスを使用した後続の呼び出しでは、エラーがスローされずにゼロエンティティが常に取得されます。私は新しいエンティティを追加し、FetchXmlを使用してフェッチする必要がある既存のエンティティを再アクティブ化し、それらは取得されません。

サービスを再開するとすぐにCrmOrganizationServiceContextの新しいインスタンスが作成され、新しいアイテムがフェッチされます。

私はここで間違っていますか?

public CrmConnector(string connectionString) 
    { 
     Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString)); 
    } 

    public void FetchStuff() 
    { 
     string fetchXml = "..."; 
     FetchExpression fetchExpression = new FetchExpression(fetchXml); 
     EntityCollection entityCollection = Context.RetrieveMultiple(fetchExpression); 
     // entityCollection.Entities is always empty following first run 
    } 

    private CrmOrganizationServiceContext Context { get; set; } 

要求されるように、唯一のカスタマイズは(これはキュープロセッサであるとして)返される項目の数を制限し、カウント属性であるXMLを取得

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="10"> 
    <entity name="xxx1"> 
     <attribute name="xxx_name" /> 
     <attribute name="createdon" /> 
     <attribute name="xxx_1" /> 
     <attribute name="xxx_2" /> 
     <attribute name="xxx_3" /> 
     <attribute name="xxx_4" /> 
     <attribute name="statecode" /> 
     <order attribute="createdon" descending="false" /> 
     <filter type="and"> 
     <condition attribute="xxx_exported" value="0" operator="eq"/> 
     </filter> 
    </entity> 
    </fetch> 
+0

をキャッシュされています私の場合は、サービスを変更して、毎回実行するように投票するたびに(10分ごとのような)、私はコンテキストを再インスタンス化し、関連するクラスを新しく始めました。それはオプションですか? – Chris

+0

完全性のために、あなたの 'FetchXml'を投稿できますか? –

+1

@Chris - 私は、毎回インスタンスを作成するために血まみれの年齢がかかるので、好きではありません:( –

答えて

3

それはやっているCrmOrganizationServiceContextですキャッシング - 私は似何かをやっ及びthoug問題の同じ種類を持っていた私は、次のように御馳走を働いた見つからないし、私のRetrieveMultipleの結果は、もはや:)

Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString)); 
Context.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled); 
関連する問題