我写了这段代码。但是我想忽略时间,我只想比较一天。
from s in sayac_okumalari
where s.okuma_tarihi == startDate && s.sayac_id == sayac_id
group s by new { date = new DateTime(((DateTime)s.okuma_tarihi).Year, ((DateTime)s.okuma_tarihi).Month, ((DateTime)s.okuma_tarihi).Day, ((DateTime)s.okuma_tarihi).Hour, 1, 1) } into g
select new
{
okuma_tarihi = g.Key.date,
T1 = g.Sum(x => x.toplam_kullanim_T1),
T2 = g.Sum(x => x.toplam_kullanim_T2),
T3 = g.Sum(x => x.toplam_kullanim_T3)
};例如:
25.02.1987 == 25.02.1987发布于 2012-07-24 14:51:43
使用s.okuma_tarihi.Value.Date == startDate.Date。这应该只允许您比较Date组件。
注释中的讨论中的更新看起来像是用户正在使用NullableType。因此更新了NullableType的解决方案。
发布于 2012-07-24 14:52:21
使用DateTime的Date属性。对于ex来说,
var date= DateTime.Now.Date;发布于 2012-07-24 15:11:44
因为您可以将s.okuma_tarihi转换为DateTime,所以我认为您可以这样做:
var sonuc = from s in sayac_okumalari
where (DateTime)s.okuma_tarihi.Date == startDate.Date && s.sayac_id == sayac_id
group s by new { date = new DateTime(((DateTime)s.okuma_tarihi).Year, ((DateTime)s.okuma_tarihi).Month, ((DateTime)s.okuma_tarihi).Day, ((DateTime)s.okuma_tarihi).Hour, 1, 1) } into g
select new
{
okuma_tarihi = g.Key.date,
T1 = g.Sum(x => x.toplam_kullanim_T1),
T2 = g.Sum(x => x.toplam_kullanim_T2),
T3 = g.Sum(x => x.toplam_kullanim_T3)
};希望能有所帮助。
https://stackoverflow.com/questions/11625554
复制相似问题