Reputation: 30303
In LINQ, I write a query for data, which is between two dates. In this case I am not getting data. When user enters same date as from date and to date the data is not displaying while there are data for that particular date.
This is my LINQ query.
var result = from MaterialStatus in materialRequistionEntities.Tbl_MatReq_NewItemReq_M
join CurrentStatus in materialRequistionEntities.Tbl_StatusMaster_M
on MaterialStatus.ReqCurStatus equals CurrentStatus.StatusId
join Employee in materialRequistionEntities.Tbl_Emp_Master_M
on MaterialStatus.Indentor equals Employee.EmpId
where (MaterialStatus.CreatedOn >= dt.Date
&& MaterialStatus.CreatedOn <= dt1.Date)
select *****************
Upvotes: 0
Views: 234
Reputation: 57
I hope it will be ok.
where (MaterialStatus.CreatedOn.Value.Date >= dt.Date && MaterialStatus.CreatedOn.Value.Date <= dt1.Date.AddDay(1))
Upvotes: 0
Reputation: 109079
You should do:
var upperDate = dt1.Date.AddDays(1);
...
where (MaterialStatus.CreatedOn >= dt.Date
&& MaterialStatus.CreatedOn < upperDate
This way the expression can be converted to a sargable SQL predicate.
Upvotes: 1
Reputation: 4655
Assuming that dt1
is in reality greater that dt
, you could use
var result = from MaterialStatus in materialRequistionEntities.Tbl_MatReq_NewItemReq_M
join CurrentStatus in materialRequistionEntities.Tbl_StatusMaster_M on
MaterialStatus.ReqCurStatus equals CurrentStatus.StatusId
join Employee in materialRequistionEntities.Tbl_Emp_Master_M
on MaterialStatus.Indentor equals Employee.EmpId
where (MaterialStatus.CreatedOn.Date >= dt.Date && MaterialStatus.CreatedOn.Date <= dt1.Date)
select *****************
Notice CreatedOn.Date
to deal with the hour/minute/seconds/milliseconds components
Upvotes: 0