2010-02-10 20 views
54

que estoy tratando de que mi declaración de LINQ para conseguirme todos los registros entre dos fechas, y no estoy muy seguro de lo que tengo que cambiar para conseguir que funcione: (a.Start >= startDate && endDate)C# LINQ Donde Fecha Entre 2 fechas

var appointmentNoShow = 
    from a in appointments 
    from p in properties 
    from c in clients 
    where a.Id == p.OID && (a.Start.Date >= startDate.Date && endDate) 
+2

[LINQ entre el operador] (http://stackoverflow.com/questions/1447635/linq-between-operator) – Soren

Respuesta

107

Sólo cambia a

var appointmentNoShow = from a in appointments 
         from p in properties 
         from c in clients 
         where a.Id == p.OID && 
         (a.Start.Date >= startDate.Date && a.Start.Date <= endDate) 
+1

doah! gracias – David

+1

De nada :) – Giorgi

+4

Hola @Giorgi: El miembro de tipo especificado 'Fecha' no se admite en LINQ to Entities. – admin

22
var appointmentNoShow = from a in appointments 
         from p in properties 
         from c in clients 
         where a.Id == p.OID 
         where a.Start.Date >= startDate.Date 
         where a.Start.Date <= endDate.Date 
2
var QueryNew = _context.Appointments.Include(x => x.Employee).Include(x => x.city).Where(x => x.CreatedOn >= FromDate).Where(x => x.CreatedOn <= ToDate).Where(x => x.IsActive == true).ToList(); 
-1

public List<tbltask> gettaskssdata(int? c, int? userid, string a, string StartDate, string EndDate, int? ProjectID, int? statusid) 
 
     { 
 
      List<tbltask> tbtask = new List<tbltask>(); 
 
      DateTime sdate = (StartDate != "") ? Convert.ToDateTime(StartDate).Date : new DateTime(); 
 
      DateTime edate = (EndDate != "") ? Convert.ToDateTime(EndDate).Date : new DateTime(); 
 
      tbtask = entity.tbltasks.Include(x => x.tblproject).Include(x => x.tbUser). 
 
       Where(x => x.tblproject.company_id == c 
 
        && (ProjectID == 0 || ProjectID == x.tblproject.ProjectId) 
 
        && (statusid == 0 || statusid == x.tblstatu.StatusId) 
 
        && (a == "" || (x.TaskName.Contains(a) || x.tbUser.User_name.Contains(a))) 
 
        && ((StartDate == "" && EndDate == "") || ((x.StartDate >= sdate && x.EndDate <= edate)))).ToList(); 
 

 

 

 
      return tbtask; 
 

 

 
     }

esta mi consulta para los registros de búsqueda basado en searchdata y entre el inicio de la fecha final,