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”
答案 0 :(得分:0)
可能对您有所帮助: - 取代
Convert.ToDateTime(E.Date).ToShortDateString()
与
Convert.ToDateTime(E.Date).ToString("yyyy-mm-dd")