2010-02-10 7 views
54

Ich versuche, meine Linq-Anweisung, um mich alle Datensätze zwischen zwei Daten zu bekommen, und ich bin mir nicht ganz sicher, was ich ändern muss, um es an die Arbeit: (a.Start >= startDate && endDate)C# Linq Wo Datum Zwischen 2 Termine

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 Zwischen Operator] (http://stackoverflow.com/questions/1447635/linq-between-operator) – Soren

Antwort

107

einfach, es ändern

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! danke – David

+1

Sie sind willkommen :) – Giorgi

+4

Hallo @Giorgi: Der angegebene Typ Mitglied 'Datum' wird nicht in LINQ to Entities unterstützt. – 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; 
 

 

 
     }

diese meine Abfrage für die Suche Datensätze anhand von search und zwischen Anfang bis zum Enddatum