我有一个linq to sql查询的问题。如果有人会帮助我,我会祈祷:)。
这是我的SQL查询:
SELECT Y.kullaniciAdi
,COUNT(A.adim_id) AS EklenenAdimlar
FROM [Adimlar] AS A
INNER JOIN Yazilimcilar AS Y ON Y.yazilimci_id = A.refYazilimci_id
INNER JOIN Durumlar AS D ON D.durum_id = A.refDurum_id
INNER JOIN AdimCalismalari AS AC ON AC.refAdim_id = A.adim_id
WHERE MONTH(eklenmeTarihi) BETWEEN 3 AND 3
AND DAY(eklenmeTarihi) BETWEEN 22 AND 29
AND YEAR(eklenmeTarihi) BETWEEN 2011 AND 2011
AND AC.refDurum_id IN (2,5)
GROUP BY A.refYazilimci_id,Y.kullaniciAdi
这是我的linq to sql查询:
var AdimCalismalari =
from Adm in db.Adimlars.AsEnumerable()
join Yzl in db.Yazilimcilars on Adm.refYazilimci_id equals Yzl.yazilimci_id
join Drm in db.Durumlars on Adm.refDurum_id equals Drm.durum_id
join AdmC in db.AdimCalismalaris on Adm.adim_id equals AdmC.refAdim_id
where
Adm.eklenmeTarihi.Value >= DateTime.Parse(dexIlkTarih.Text) &&
Adm.eklenmeTarihi.Value <= DateTime.Parse(dexSonTarih.Text)
&& (AdmC.refDurum_id == 2 || AdmC.refDurum_id == 5)
group Adm by new { yazilimci = Yzl.kullaniciAdi, AdimSayi = Adm.adim_id }
into AdimToplam
select new
{
yazilimci = AdimToplam.Key.yazilimci,
AdimSayi = AdimToplam.Key.AdimSayi
};
我的linq查询返回null结果但是我的sql查询返回3行。你对我的问题有任何想法吗?
KR,
Çağın
答案 0 :(得分:3)
我看到一个潜在的问题:
当dexIlkTarih.Text
为2011-03-22时,dexSonTarih.Text
为2011-03-29,Adm.eklenmeTarihi.Value
为2011-03-29 01:00,即它与您的上限具有相同的日期但也有一段时间,它不会被退回,因为:
2011-03-29 = 2011-03-29 00:00&lt; 2011-03-29 01:00
这是您的SQL和LINQ查询之间的明确区别。
答案 1 :(得分:1)
傻傻的,
我从Adimlars删除.AsEnumerable()并解决了。谢谢你的建议。
KR,
Çağın