0
我想換掉這個SQL命令:LINQ的GROUP BY和內部連接
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)
});
你能幫我嗎?
您使用的'join'顯然是**內部連接,您應該首先描述您想要執行的操作,以及查詢如何爲您工作。 –
這可能有幫助... http://www.devexpress.com/Support/Center/Example/Details/E1883 – daehaai
我有SQL查詢,我想重寫它由linq。這個sql命令只加入兩個表,並在它們之間進行分組。問題在小組中。當我在一個表下使用group時,一切正常,linq commant返回與sql命令相同的結果。但是當我想要連接兩個表然後按H.Ucet(例如)分組時,它會返回其他結果作爲我的sql命令。結果與使用左連接時相同,但我需要默認的內連接。 – mik3s