我正在尝试列出直到当前日期(最近的约会)的最后5条记录。这是我的控制器运行良好的方法,但是如何仅对5条记录进行过滤,而这些记录的日期在今天之前。
using (var db = new MaindbModelDataContext())
{
var patient = db.Patients.FirstOrDefault(u => u.Email == (String)Session["UserEmail"]);
var listrecent = from y in db.Appointments
where y.PatientNo == patient.PatientNo
select y;
var TempRecent = new List<Models.AppModel>();
foreach (var item in listrecent)
{
var Temp = new Models.AppModel();
Temp.AppNo = item.AppNo;
Temp.PatientNo = (Int32)item.PatientNo;
Temp.Date = (DateTime)item.Date;
Temp.Status = item.Status;
Temp.Description = item.Description;
TempRecent.Add(Temp);
}
return View(TempRecent);
}
}
else
{
return RedirectToAction("RegAndLogin", "User");
}
}
}
这是我的看法
@model IEnumerable<DentAppSys.Models.AppModel>
@using System.Web.Helpers
<section class="Patient-Dashboard">
<div id="dashboard_left">
<h1> Recent Appointments</h1>
@{
var Mygrid = new WebGrid(Model, selectionFieldName: "SelectedRow");
}
@Mygrid.GetHtml(
displayHeader: true,
alternatingRowStyle: "alt",
selectedRowStyle: "select",
mode: WebGridPagerModes.All,
columns: Mygrid.Columns
(
Mygrid.Column("Appointment No", "Appointment No",format: @<text>@item.AppNo</text>),
Mygrid.Column("Patient No", "Patient No", format: @<text>@item.PatientNo</text>) ,
Mygrid.Column("Description", "Description", format: @<text>@item.Description</text>),
Mygrid.Column("Date", "Date", format: @<text>@item.Date.ToString("MM/dd/yyyy")</text>),
Mygrid.Column("Status", "Status", format: @<text>@item.Status</text>)
))
</div>
<div id="dashboard_right">
<br/>
<h1>Incoming Appointments</h1>
</div>
</section>
我相信您的linq语句中的类似内容应该起作用:
var listrecent = (from y in db.Appointments
where y.PatientNo == patient.PatientNo
where y.Date < DateTime.Today
orderby y.Date descending
select y).Take(5);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句