5

私はこのコードを書きました。しかし、私は時間を無視したい、私は日だけを比較したい。

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
4

5 に答える 5

17

を使用しますs.okuma_tarihi.Value.Date == startDate.Date。これにより、日付コンポーネントのみを比較できるようになります。

更新コメントの議論から、ユーザーがNullableTypeを使用しているように見えます。したがって、NullableTypeのソリューションを更新しました。

于 2012-07-24T06:51:42.823 に答える
8

DateDateTime のプロパティを使用します。たとえば、

var date= DateTime.Now.Date;
于 2012-07-24T06:52:20.873 に答える
2

DateTimeに変換できるので、次のことができるs.okuma_tarihiと思います。

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)
        };

それが役に立てば幸い。

于 2012-07-24T07:11:43.703 に答える