请有人协助下面的查询。我试图选择每个客户端的所有收据总和。但是,我的select部分中的'Total ='子查询不起作用,并且出现以下错误:使用linq执行求和子查询
无法创建类型为'AppName.Domain.Entities.AccountingEntry'的常量值。只有原始类型或枚举类型在此上下文中受支持。
我已经尝试过在查询后做一个ToList(),但这会导致同样的问题。使用linq选择Sum作为子查询的标准方法是什么?
var receipts = (from ae in repo.AccountingEntries
join c in repo.Clients on ae.ClientId equals c.ClientId
join m in repo.Memberships on c.MembershipId equals m.MembershipId
where
(ae.EntryDate <= start) &&
(ae.ClientId != null) &&
(ae.AccountingEntryTypeId == (byte)Shared.AccountingEntryTypes.Receipt)
select new AppName.Reports.Clients.AgeAnalysis.Receipt
{
ClientId = (Guid)ae.ClientId,
Client = c.FirstName + " " + c.LastName,
Membership = c.Membership.Name,
Total = (from ae2 in repo.AccountingEntries where ae2.ClientId == ae.ClientId select ae2.Total).Sum()
});
感谢, 加里
什么类型是Total? – 2013-03-26 13:28:11
查询没有计算总数? – 2013-03-26 13:34:09
Total是一个小数,是的,没有Total子查询部分查询运行正常。 – Gary 2013-03-27 09:41:53