【发布时间】:2018-08-02 13:54:44
【问题描述】:
我想删除两个日期之间的记录。我使用 Fetchxml 表达式来获取两个日期之间每条记录的 GUID,然后我使用 service.Delete。这是我的代码:
string fetchXml = @" <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='new_units'>
<link-entity name='new_alterunitorder' from ='new_orderlineid' to = 'new_unitsid' >
<attribute name='new_alterunitorderid' />
<filter type='and'>
<condition attribute='new_orderdate' operator='on-or-after' value='" + startDate.ToShortDateString() + @"' />
<condition attribute='new_orderdate' operator='on-or-before' value='" + endDate.ToShortDateString() + @"' />
<condition attribute='new_orderlineid' operator='eq' uiname='" + uiName + @"' uitype='new_units' value='" + unitOrderId + @"' />
</filter>
</link-entity>
</entity>
</fetch>";
EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchXml));
//Delete the collection
foreach (var id in result.Entities)
{
var entRef = id.GetAttributeValue<EntityReference>("new_alterunitorderid");
var guid = (Guid)entRef.Id;
service.Delete("new_alterunits", guid);
}
FetchXML 有 5000 条记录的限制,我该如何绕过?!我还读到使用service.Delete 循环不是推荐的批量删除方式。请帮助我找到实现我想做的最好的方法!
【问题讨论】:
标签: c# dynamics-crm microsoft-dynamics dynamics-365 dynamics-crm-365