So I have this statement
SearchResults = (from s in dbContext.tbl_ShippingProgram
where s.eta_date.Date > DateTime.Now.Date.AddMonths(-TimePeriod.Value)
select s).ToList();
Where SearchResults is defined as
public List<tbl_ShippingProgram> SearchResults { get; set; }
And where TimePeriod.Value is a int
I'm having difficulties figuring out why this doesn't work, there's nothing wrong the with just selecting all values since
SearchResults = (from s in dbContext.tbl_ShippingProgram
select s).ToList();
Works perfectly fine. Any and all help is appreciated <3
EDIT - The issue is that it's not returning anything where it definately should be, checked the values in the db and the calculated DateTime.Now value and it should be returning something
Try DateTime.Now.AddMonths(-TimePeriod.Value).Date
I think you want the date portion of the datetime after the adjustment. This trips me up all the time too...
Couple of other things to try if this doesn't help:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.