【发布时间】:2011-11-23 21:27:01
【问题描述】:
目前,我将回购中的所有内容作为列表返回。我希望将这些更改为 IQueryable,以便人们可以优化结果而不会受到另一个 sql 请求的影响(我正在使用 nhibernate)。
我有一个问题要让每个人的生活更轻松我的回购中有这样的东西
public List<CalendarAppointment> GetAppointment(Student student, DateTime start, DateTime end)
{
List<CalendarAppointment> appointments = session.Query<CalendarAppointment>().Where(x => x.Student.Id == student.Id
&& x.Start.Date >= start.Date && x.End.Date <= end.Date)
.Take(QueryLimits.Appointments).ToList();
return appointments.ConvertToLocalTime(student);
}
public static List<CalendarAppointment> ConvertToUtcTime(this List<CalendarAppointment> appointments, Student student)
{
if (student != null)
{
TimeZoneInfo info = TimeZoneInfo.FindSystemTimeZoneById(student.TimeZoneId);
foreach (var appointment in appointments)
{
appointment.Start = TimeZoneInfo.ConvertTimeToUtc(appointment.Start,info);
appointment.End = TimeZoneInfo.ConvertTimeToUtc(appointment.End,info);
}
}
return appointments;
}
所以我得到了当前的结果,然后将时间转换为当地时间。这样我们就不用担心了。
如果我使用 IQueryable 执行此操作会发生什么。无论如何它会关闭并触发sql吗?
【问题讨论】:
标签: nhibernate list iqueryable