2010-02-10 34 views
54

Tôi đang cố gắng lấy bản kê LINQ để lấy tất cả hồ sơ giữa hai ngày, và tôi không chắc mình cần thay đổi gì để làm việc: (a.Start >= startDate && endDate)C# Linq Nơi Ngày Giữa 2 Ngày

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 giữa Toán tử] (http://stackoverflow.com/questions/1447635/linq-between-operator) – Soren

Trả lời

107

Chỉ cần thay đổi nó để

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! cảm ơn bạn – David

+1

Bạn được chào đón :) – Giorgi

+4

Hi @Giorgi: Thành viên loại được chỉ định 'Ngày' không được hỗ trợ trong 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; 
 

 

 
     }

này truy vấn của tôi cho các hồ sơ tìm kiếm dựa trên searchdata và giữa lúc bắt đầu đến ngày kết thúc

Các vấn đề liên quan