【问题标题】:Pulling in data using Entity Framework to Nreco pivotdata使用实体框架将数据拉入 Nreco 数据透视表
【发布时间】:2019-08-22 22:17:03
【问题描述】:

我正在尝试测试 NReco.PivotData 的内存立方体。我们现有的流程是使用实体框架,并且能够提取数据,但我找不到将其放入多维数据集的正确方法。

尝试将数据转换为列表、数组、可枚举和 json

var pvtData = new PivotData(
      new[] { "closeDate", "opportunityName" },
      new SumAggregatorFactory("amount"), true);

  var allRows = (from c in newContext.MCrmOpportunity select c).AsEnumerable();

  pvtData.ProcessData(allRows);

错误在最后一行。

错误 CS1503 参数 1:无法从“System.Collections.Generic.IEnumerable”转换 到'System.Collections.Generic.IEnumerable System.Collections.Generic.IDictionary>'

【问题讨论】:

    标签: c# nreco


    【解决方案1】:

    PivotData.ProcessData method 只接受一个参数,需要IEnumerable<DataRow>IEnumerable<IDictionary<string, Object>>。要从模型集合中聚合数据,您需要使用 ProcessData(IEnumerable data, Func getValue) 重载:

    pvtData.ProcessData(allRows, new ObjectMember().GetValue);
    

    (假设“closeDate”、“opportunityName”、“amount”是MCrmOpportunity模型的属性)

    请注意,使用“ProcessData”方法聚合数据时的方法仅适用于少量模型;如果有许多数据库记录,最好在数据库级别执行聚合(使用 SQL GROUP BY)并将聚合结果加载到 PivotData 类中,如here 所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 1970-01-01
      相关资源
      最近更新 更多