FetchExpression 结果似乎已被缓存,如何防止这种情况发生?

发布于 2024-12-20 08:39:00 字数 1711 浏览 2 评论 0原文

我在 Windows 服务内的 CrmOrganizationServiceContext 上使用 FetchExpression 来针对 CrmOrganizationServiceContext 上的 RetrieveMultiple 操作来从队列中获取和处理项目。

第一次运行时,它会获取要正确处理的项目。在使用相同 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 属性,它限制返回的项目数(因为这是一个队列处理器)

  <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>

I am using a FetchExpression against a RetrieveMultiple operation on a CrmOrganizationServiceContext within a windows service to fetch and process items out of a queue.

The first time this runs this fetches the items to be processed correctly. On subsequent calls using the same CrmOrganizationServiceContext instance it always retrieves zero entities with no errors thrown. I have added in new entities and reactivated existing ones that should be fetched using the FetchXml and they aren't retrieved.

As soon as I restart my service it creates a new instance of the CrmOrganizationServiceContext and fetches the new items.

What am I doing wrong here?

   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; }

Fetch Xml as requested, the only customisation is the count attribute which limits the number of items being returned (as this is a queue processor)

  <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫尐诺 2024-12-27 08:39:00

正在执行缓存的是 CrmOrganizationServiceContext - 我发现以下内容很有效,并且我的 RetrieveMultiple 的结果不再被缓存:)

Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString));
Context.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);

It is the CrmOrganizationServiceContext that is doing the caching - I found the following worked a treat and the results of my RetrieveMultiple are no longer cached :)

Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString));
Context.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文