0

尝试获取记录时出现此错误

The 'Rollup' method does not support entities of type 'new_X'.

这是我的代码

RollupRequest req = new RollupRequest();
QueryExpression qe = new QueryExpression();
qe.EntityName = "new_x";
qe.ColumnSet = new ColumnSet(true);
req.Query = qe;
req.Target = new EntityReference("new_newpost", new Guid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
req.RollupType = RollupType.Related;
RollupResponse resp = (RollupResponse)xrm.Execute(req);

如何获取汇总查询的结果

提前致谢


对于自定义实体,您可以进行休耕

var rollupQuery = xrm.GoalRollupQuerySet.Where(c => c.Id == x.new_RecordstoRun.Id).First();
var result = xrm.RetrieveMultiple(new FetchExpression(rollupQuery.FetchXml));

但是 - 我怎样才能添加一个“跳过”或“采取”Linq?

4

2 回答 2

1

您只能在MSDNRollupRequest上描述的特定实体集上使用。

所以这对“new_x”或“new_newpost”永远不起作用。

本文RollupRequest使用机会和帐户进行了正确的演示。

我建议只创建您自己的自定义QueryExpression来检索所有“new_x”,然后使用LinkEntities.

于 2012-11-05T16:34:20.010 回答
0

这是我的代码,所以得到 RollupQuery 的结果

List<Guid> GetAllResultsFromRollupQuery(XrmServiceContext xrm, Guid rollupQueryId)
{
    var rollupQuery = xrm.GoalRollupQuerySet.Where(v => v.Id == rollupQueryId).First();
    var qa = GetQueryExpression(xrm, rollupQuery.FetchXml);

    qa.PageInfo.Count = 1000;
    qa.ColumnSet.AddColumn(rollupQuery.QueryEntityType + "id");

    var result = new List<Guid>();
    EntityCollection ec = null;

    do
    {
        ec = xrm.RetrieveMultiple(qa);
        ec.Entities.ToList().ForEach(v => result.Add((Guid)v.Attributes[rollupQuery.QueryEntityType + "id"]));
        qa.PageInfo.PageNumber += 1;

    } while (ec.MoreRecords == true);


    return result;
}

QueryExpression GetQueryExpression(XrmServiceContext xrm, string fetchXml)
{
    var req = new FetchXmlToQueryExpressionRequest { FetchXml = fetchXml };
    var result = (FetchXmlToQueryExpressionResponse)xrm.Execute(req);
    return result.Query;
}
于 2012-11-07T09:21:08.050 回答