LINQ 连接 +分组依据 +和

发布于 2024-08-22 19:40:58 字数 1110 浏览 5 评论 0原文

我有两个 LINQ 语句,我想将它们合二为一,但我一生都无法让它工作。

我无法在第一个语句中使分组起作用。 它抱怨 TotalBuyTotalSell 属性不存在,但没有抱怨 AmountTCAmountAUD

这应该很简单。有什么想法吗?

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)))
};

附带说明一下,ItineraryItemRecordsTransactionRecords 是由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝在阴天搁浅。 2024-08-29 19:40:58

一个小错误,已更正:

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) 
       , TotalBuy = g.Sum(i => i.TotalBuy) 
       //, TotalSell = g.Sum(i => ii.TotalSell) 
       , TotalSell = g.Sum(i => i.TotalSell) 
       , PaidTC = (0 - (g.Sum(t => t.AmountTC))) 
       , PaidAUD = (0 - (g.Sum(t => t.AmountAUD))) 
   }; 

我建议不要重复使用标识符 - 将有助于避免将来出现这些错误。

A minor mistake, corrected:

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) 
       , TotalBuy = g.Sum(i => i.TotalBuy) 
       //, TotalSell = g.Sum(i => ii.TotalSell) 
       , TotalSell = g.Sum(i => i.TotalSell) 
       , PaidTC = (0 - (g.Sum(t => t.AmountTC))) 
       , PaidAUD = (0 - (g.Sum(t => t.AmountAUD))) 
   }; 

I recommend against re-using identifiers - will help avoid these mistakes in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文