LINQ 连接 +分组依据 +和
我有两个 LINQ 语句,我想将它们合二为一,但我一生都无法让它工作。
我无法在第一个语句中使分组起作用。 它抱怨 TotalBuy
和 TotalSell
属性不存在,但没有抱怨 AmountTC
和 AmountAUD
。
这应该很简单。有什么想法吗?
var itineraryItems =
from ii in this.ItineraryItemRecords
join t in this.TransactionRecords on ii.OperatorID equals t.
TransactionActor.OperatorID into g select new {
OperatorID = ii.OperatorID, TotalBuy = g.Sum(i = >ii.TotalBuy)
, TotalSell = g.Sum(i = >ii.TotalSell)
, PaidTC = (0 - (g.Sum(t = >t.AmountTC)))
, PaidAUD = (0 - (g.Sum(t = >t.AmountAUD)))
};
var itineraryItemz =
from i in itineraryItems group i by i.OperatorID into g select new {
OperatorID = g.Key, TotalBuy = g.Sum(i = >i.TotalBuy)
, TotalSell = g.Sum(i = >i.TotalSell)
, PaidTC = (0 - (g.Sum(i = >i.PaidTC)))
, PaidAUD = (0 - (g.Sum(i = >i.PaidAUD)))
};
附带说明一下,ItineraryItemRecords
和 TransactionRecords
是由 SubSonic
处理的类集合。
这确实应该很简单,因此我们将不胜感激。
问候, 约翰
I have two LINQ statements that I would like to make into one, but for the life of me I can't get it to work.
I can't get the grouping to work in the first statement.
It complains that the TotalBuy
and TotalSell
properties aren't there, although doesn't complain about AmountTC
and AmountAUD
.
This should be simple. Any thoughts?
var itineraryItems =
from ii in this.ItineraryItemRecords
join t in this.TransactionRecords on ii.OperatorID equals t.
TransactionActor.OperatorID into g select new {
OperatorID = ii.OperatorID, TotalBuy = g.Sum(i = >ii.TotalBuy)
, TotalSell = g.Sum(i = >ii.TotalSell)
, PaidTC = (0 - (g.Sum(t = >t.AmountTC)))
, PaidAUD = (0 - (g.Sum(t = >t.AmountAUD)))
};
var itineraryItemz =
from i in itineraryItems group i by i.OperatorID into g select new {
OperatorID = g.Key, TotalBuy = g.Sum(i = >i.TotalBuy)
, TotalSell = g.Sum(i = >i.TotalSell)
, PaidTC = (0 - (g.Sum(i = >i.PaidTC)))
, PaidAUD = (0 - (g.Sum(i = >i.PaidAUD)))
};
As a side note, ItineraryItemRecords
and TransactionRecords
are Collections of classes handled by SubSonic
.
This really should be simple, so any help would be appreciated.
Regards,
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个小错误,已更正:
我建议不要重复使用标识符 - 将有助于避免将来出现这些错误。
A minor mistake, corrected:
I recommend against re-using identifiers - will help avoid these mistakes in the future.