0

我想替换这个 SQL 命令:

string dotazBankUcty = @"SELECT 
     H.UCET, 
     SUM(H.KON_STAV_MD) AS KON_STAV_MD, 
     SUM(H.KON_STAV_DAL) AS KON_STAV_DAL , 
     SUM(H.KON_STAV_MD_MENA) AS KON_STAV_MD_MENA, 
     SUM(H.KON_STAV_DAL_MENA) AS KON_STAV_DAL_MENA, 
     MAX(UBUC.KOD_MENY) AS KOD_MENY 
     FROM UHLAVAKT H 
     inner join UBUC on H.UCET = UBUC.UCET GROUP BY H.UCET";

使用 LINQ 命令。我试过这个,但它返回一个左连接而不是我想要的内连接。

var uhlavAktQuery = new XPQuery<UHLAVAKT>(CoreHelper.DataSession);

var ubucQuery = new XPQuery<UBUC>(CoreHelper.DataSession);

var resultBankyUcty = (from h in uhlavAktQuery
    join u in ubucQuery on h.CompoundKey1.UCET equals u.UCET
    group new { h, u } by new { h.CompoundKey1.UCET } into gUcty
                    select new
                    {
                    Ucet = gUcty.Key.UCET,
                    KON_STAV_MD = gUcty.Sum(k => k.h.KONSTAVMD),
                    KON_STAV_DAL = gUcty.Sum(k => k.h.KONSTAVDAL),
                    KON_STAV_MD_MENA = gUcty.Sum(k => k.h.KONSTAVMDMENA),
                    KON_STAV_DAL_MENA = gUcty.Sum(k => k.h.KONSTAVDALMENA),
                    KOD_MENY = gUcty.Max(k => k.u.KODMENY)
                    });

你能帮我吗?

4

1 回答 1

1

当我在努力了解与 LINQ 的连接时,我发现 CodeProject 上的以下文章非常有用且很有帮助:

LINQ 扩展连接

在包括图表在内的示例的帮助下,他解释了连接是什么,并为 IEnumerable 提供了实现各种连接查询的通用扩展方法。

于 2013-10-15T10:14:30.857 回答