Linq to Entities 从 2 个总和中查询总和

Linq to Entities query sum from 2 sums

你好,这是一个使用 linq to entities 执行的 sql 查询:

 private void GetDatas()
    {
        using(GSUITEEntities dc=new GSUITEEntities())
        {
            try
            {
                var query = from ent in dc.STOCK_ENT
                            join det in dc.STOCK_DET on ent.ENT_ID equals det.ENT_ID
                            join art in dc.FICHES_ARTICLES on ent.ART_CODE equals art.ART_CODE
                            join cli in dc.CLIENTS on ent.ENT_PROP equals cli.CLI_CODE
                            join seq in dc.MVTS_SEQUENCE on ent.ENT_ID equals seq.ENT_ID
                            join entr in dc.ENTREES_STOCKS on art.ART_CODE equals entr.ART_CODE                                
                            where seq.SEQ_STATUT != "V" && cli.CLI_CODE == "0030000"
                            && entr.ENTSTK_DATE_DEM == null
                            group new { ent, det, art, cli, seq, entr} by new
                            {
                                art.ART_CODE,
                                art.ART_LIBELLE1
                            } into grouped
                            let sumEntr=grouped.Sum(x=>x.det.DET_PNET)
                            where sumEntr<2000
                            orderby grouped.Key.ART_LIBELLE1
                            select new
                            {
                                code=grouped.Key.ART_CODE,
                                lib=grouped.Key.ART_LIBELLE1,
                                pnet=sumEntr,
                                pnetCong=grouped.Sum(x=>x.entr.ENTSTK_PNET)
                                // pnetTotal=pnet + pnetCong ; How to do that ??
                            };
            }
            catch (Exception)
            {

                throw;
            }
        }
    }

最后一行是评论。我想要一个计算字段来对 2 个分组字段求和。 pnet + pnetCong。 这怎么可能 ? 感谢您的帮助。

为什么不引入另一个透明标识符并使​​用它呢?

...
let sumEntr=grouped.Sum(x=>x.det.DET_PNET)
let sumEntstkPnet=grouped.Sum(x=>x.entr.ENTSTK_PNET)
where sumEntr<2000
orderby grouped.Key.ART_LIBELLE1
select new
{
    code=grouped.Key.ART_CODE,
    lib=grouped.Key.ART_LIBELLE1,
    pnet=sumEntr,
    pnetCong=sumEntstkPnet
    pnetTotal=sumEntr+sumEntstkPnet
};