c# - Entity Framework DateTIme Query -


i'm having issue linq subquery return invalid data when adding in datetime checks part of where clause.

this original query , returning 0; because result set null

var subquery =      (from item in g      e in item.entry     e.type == 1         && e.entrytype == 2        && item.startdate >= priormonthstartofday        && item.enddate <= startofdayqueryparam    select e.amount).sum() ?? 0m; 

i modified query see data was; here query , resulting dataset.

var subquery =      (from item in g      e in item.entry     e.type == 1         && e.entrytype == 2    select new            {                amount = e.amount,                sd = item.startdate,                ed = item.enddate,                qd = priormonthstartofday           }; 

no date restriction results

so added in start date comparison , results below. priormonthstartofday datetime value of 12/1/2015 12:00:00 am

var subquery =      (from item in g      e in item.entry     e.type == 1         && e.entrytype == 2        && item.startdate >= priormonthstartofday    select new            {                amount = e.amount,                sd = item.startdate,                ed = item.enddate,                qd = priormonthstartofday           }; 

start date restriction

why date comparison not behaving expected? given value of priormonthstartofday, expect result set same last 2 queries. i'm guessing has time equal comparison because if subtract second priormonthstartofday result sets match again.

the logical explanation priormonthstartofday and/or startofdayqueryparam variables contain time part not shown in debugger. note default milliseconds part not shown, not mention ticks.

to 100% sure comparing against dates, change date part of criteria to

&& item.startdate >= priormonthstartofday.date && item.enddate <= startofdayqueryparam.date 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -