0
 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”

4

1 回答 1

0

可能对您有帮助:- 替换

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

Convert.ToDateTime(E.Date).ToString("yyyy-mm-dd")
于 2013-07-19T09:38:45.570 回答