FetchExpression 结果似乎已被缓存,如何防止这种情况发生?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正在执行缓存的是
CrmOrganizationServiceContext
- 我发现以下内容很有效,并且我的 RetrieveMultiple 的结果不再被缓存:)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 :)