C# FetchExpression结果似乎已缓存,如何防止这种情况?

C# FetchExpression结果似乎已缓存,如何防止这种情况?,c#,dynamics-crm,dynamics-crm-2011,dynamics-crm-online,xrm,C#,Dynamics Crm,Dynamics Crm 2011,Dynamics Crm Online,Xrm,我在windows服务中对CrmOrganizationServiceContext上的RetrieveMultiple操作使用FetchExpression从队列中提取和处理项目 第一次运行时,它将获取要正确处理的项目。在使用相同的CrmOrganizationServiceContext实例进行后续调用时,它总是检索零个实体,而不会抛出错误。我添加了新的实体,并重新激活了现有的实体,这些实体应该使用FetchXml获取,但它们不会被检索 一旦我重新启动服务,它就会创建CrmOrganizat

我在windows服务中对
CrmOrganizationServiceContext
上的
RetrieveMultiple
操作使用
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,唯一的自定义是count属性,它限制返回的项目数(因为这是一个队列处理器)


CrmOrganizationServiceContext
在进行缓存-我发现以下内容起了作用,并且我的RetrieveMultiple的结果不再被缓存:)


我做了类似的事情,也有同样的问题,但在我的例子中,我改变了我的服务,以便每次轮询它运行(大约每10分钟一次),我都会重新实例化上下文和相关类以获得一个新的开始,这是一个选项吗?为了完整性,你可以发布你的
FetchXml
?@Chris-我不想这样做,因为每次创建实例都需要花费大量的时间:(是的,正如我告诉我的同事,
FetchXml
是一个技术术语:)@Chris每次都尝试重新创建实例,但它仍然无法获取实体,所以发生了其他事情。。。
  <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>
Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString));
Context.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);