I try to get the entries of my mssql table from the past 7 days with entity framework in c#.
For that i tried:
var query = context.tbl.Where(fld => fld.date >= (DateTime.Now.AddDays(-7)));
This doesn't work at all. I thought that if the date from the record was bigger or equal than date.now - 7 days, it should give me back all entries from the past 7 days.
DateTime.AddDays()
cannot be converted to a store expression by Entity Framework. I'm assuming this is what you mean when you say it doesn't work?
Try this:
var dateTime = DateTime.Now.AddDays(-7);
var query = context.tbl.Where(fld => fld.date >= dateTime);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With