2012-11-05 145 views
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到這一點?

回答

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

您只能在MSDN上描述的某組實體上使用RollupRequest

所以這將永遠不會爲「new_x」或「new_newpost」工作。

This article有一個正確的演示RollupRequest使用機會和帳戶。

我建議您創建自己的自定義QueryExpression以檢索所有「new_x」,然後鏈接到「new_newpost」,並使用LinkEntities

+0

謝謝,看我的答案 – Yacov