I have the following model. I am trying to get all the records of vehicles , the MOT dated coming under between two dates . I want to give where condition in GetAll method linq
public class Vehicles { [Key] public int Id { get; set; } [Required] public string Make { get; set; } [Required] public string Model { get; set; } [Required] public string RegNo { get; set; } [Required] public string VehicleName {get;set;} public DateTime? MOTDate { get; set; } }
Repository
public IEnumerable<T> GetAll(Expression<Func<T, bool>> filter = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, string includeProperties = null) { IQueryable<T> query = dbSet; if (filter != null) { query = query.Where(filter); } if (includeProperties != null) { foreach (var includeProp in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProp); } } if (orderBy != null) { return orderBy(query).ToList(); } return query.ToList(); }
Controller
datetime datefrom
datetime dateto
var VehileList = VehicleRepo.GetAll() // how can I give the where condition between datefrom and dateto, please help