我可以在DataGridView中汇总EntityFramework Navigation列

时间:2012-04-26 20:21:25

标签: entity-framework-4 datagridview asp.net-4.0

我有两个表/实体,event和eventRegistrations。我有一个显示事件的gridview,但我希望它有一个总结eventRegistrations.SomeNumber的列。

我可以使用导航对象获取eventRegistrations的数量。

我怎样才能得到这笔钱?

2 个答案:

答案 0 :(得分:0)

如果您可以使用event.EventRegistrations.Count()对事件注册进行统计,则应该能够使用Sum的LINQ IEnumerable<T>扩展方法获取总和:

var sum = event.EventRegistrations.Sum(er => er.SomeNumber);

答案 1 :(得分:0)

像这样处理:

public string GetRegSum(object _eventReg)
{
System.Collections.Generic.List<FormRouterData.family_fishing_reg> theseRegs = (System.Collections.Generic.List<FormRouterData.family_fishing_reg>)_eventReg;
var sum = theseRegs.Sum(er => int.Parse(er.num_group));
if (sum == 0) { return string.Empty; }
else { return sum.ToString(); }
}