I try to select records in database in 60 days 30 days 20 days differents in current date.
Please see this query in below.
var uploads = (
from files in _fileuploadRepository.Table
join product in _productRepository.Table on files.Event equals product.Id
where
(
product.EventDate != null &&
(product.EventDate.Subtract(DateTime.Now).Days <= 60 && product.EventDate.Subtract(DateTime.Now).Days >= 60) ||
(product.EventDate.Subtract(DateTime.Now).Days <= 30 && product.EventDate.Subtract(DateTime.Now).Days >= 30) ||
(product.EventDate.Subtract(DateTime.Now).Days <= 20 && product.EventDate.Subtract(DateTime.Now).Days >= 20))
&&
files.IsSkiped == false
select files;
).ToList();
But a error occurred this query.
I am clueless. Please Help.
You could use the EntityFunctions.DiffDays
method
EntityFunctions.DiffDays(product.EventDate, DateTime.Now) //this will return the difference in days
UPDATE
EntityFunctions is now obsolete so you should use DBFunctions instead.
System.Data.Entity.DbFunctions.DiffDays(product.EventDate, DateTime.Now)