I have employee salary table that contains :
public partial class S_EmployeeSalary
{
public int SalaryId { get; set; }
public int TypeId
Depending if you want the last month or last 30 days (question is unclear)
This is for the previous month:
var startOfTthisMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
var firstDay = startOfTthisMonth.AddMonths(-1);
var lastDay = startOfTthisMonth.AddDays(-1);
IQueryable<S_EmployeeSalary> moduleItems = db.S_EmployeeSalary
.Include(x => x.C_UserItems)
.Where(x => x.TypeId == typeId &&
x.SalaryDate >= firstDay &&
x.SalaryDate <= lastDay);
This is for the previous 30 days:
var firstDay = DateTime.Today.AddDays(-30);
IQueryable<S_EmployeeSalary> moduleItems = db.S_EmployeeSalary
.Include(x => x.C_UserItems)
.Where(x => x.TypeId == typeId &&
x.SalaryDate >= firstDay);
looks like this part is not going to return a result since it cant be bigger and smaller than 30 at the same time.
DbFunctions.DiffDays(x.SalaryDate, DateTime.Now) > 30 && DbFunctions.DiffDays(x.SalaryDate, DateTime.Now) < 30)