在lambda表达式中按日期过滤jqgrid中的数据

时间:2013-07-19 09:32:49

标签: asp.net-mvc

 public List<Email> GetEmailAccountDetailByIDWithSorting(
                                            long EmailFolderID,
                                            string subject, 
                                            string date, 
                                            string sortColumn, 
                                            string sortOrder,
                                            int pageSize,
                                            int pageIndex,
                                            out int totalRecords)
     {

var Emails = db.Emails
               .Where(E => E.Subject.Contains(subject) &&   
                           Convert.ToDateTime(E.Date).ToShortDateString() == date && 
                           E.EmailFolderId == EmailFolderID)
               .OrderBy(u => u.Subject)
               .ThenBy(u => u.Subject);


        switch (sortColumn)
        {
            case "Subject":
                Emails = (sortOrder == "desc") ? Emails.OrderByDescending(u => u.Subject) : Emails.OrderBy(u => u.Subject);
                break;
            case "Date":
                Emails = (sortOrder == "desc") ? Emails.OrderByDescending(u => u.Date) : Emails.OrderBy(u => u.Date);
                break;
            default:
                break;
        }
        totalRecords = Emails.Count();
        return Emails.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
    }

在我的linq查询字符串输入日期是“2013-07-15”如何将E.Date数据库日期转换为输入日期格式。在此查询数据库日期,如“2013-07-15 11:35:48.000”

1 个答案:

答案 0 :(得分:0)

可能对您有所帮助: - 取代

Convert.ToDateTime(E.Date).ToShortDateString()

Convert.ToDateTime(E.Date).ToString("yyyy-mm-dd")