【发布时间】:2011-12-20 23:29:05
【问题描述】:
我正在尝试对列表进行小计,其中某些列需要求和或平均,而其他列与小计无关,例如股票名称。
我遇到了一个错误
"最佳重载方法匹配 'System.Collections.Generic.List.Add(AnonymousType#1)' 有一些无效的参数 参数 '1': 不能从 'AnonymousType#2' 到 'AnonymousType#1'"
在 Sage 200 查询生成器中运行它时,看不到我做错了什么。
如果我在 Linqpad 中尝试它,它会告诉我“名称 'cxt' 在当前上下文中不存在”
有什么想法吗?谢谢!
var q = from d in cxt.K3_StockProfitMarginByCustomers
select new
{
d.CustomerAccountName,
d.CustomerAccountNumber,
d.Code,
d.Name,
d.Profit,
d.QuantitySold,
d.TotalCost,
d.TotalRevenue,
d.MARGIN,
d.SLCustomerAccountID,
d.SOPOrderReturnID,
d.SOPOrderReturnLineID
};
q = q.Distinct();
var l = q.ToList();
var summary = new
{
CustomerAccountName = "",
CustomerAccountNumber = "",
Code = "",
Name = "",
Profit = (Decimal)q.Sum(o => o.Profit),
QuantitySold = (Decimal)q.Sum(o => o.QuantitySold),
TotalCost= (Decimal)q.Sum(o => o.TotalCost),
TotalRevenue= (Decimal)q.Sum(o => o.TotalRevenue),
MARGIN = (Decimal)q.Average(o => o.MARGIN),
SLCustomerAccountID=(String)"",
SOPOrderReturnID=(String)"",
SOPOrderReturnLineID=(String)""
};
l.Add(summary);
return l.AsQueryable();
【问题讨论】: