尝试获取记录时出现此错误
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));
但是 - 如何添加“Skip”或“Take”Linq?
答案 0 :(得分:1)
您只能在MSDN上描述的某组实体上使用RollupRequest
。
因此,这对“new_x”或“new_newpost”无效。
This article正确展示了RollupRequest
使用商机和帐户。
我建议您创建自己的自定义QueryExpression
以检索所有“new_x”,然后使用LinkEntities
链接到“new_newpost”。
答案 1 :(得分: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;
}