我的应用程序有一个内置的日历系统,并为他们的数据库架构是这样的:LINQ的 - 开始有开始和长度属性日历事件
CalendarItem(CalendarItemId bigint, Start datetime, Length int, Blargh nvarchar(MAX))
Start
是UTC日期时间价值的情况下启动时,并且Length
是以秒为单位的事件的长度。全天活动开始于0000h,长度为86400.
我正在使用Linq与实体框架,我想查找日期范围内的事件。很容易找到在两个日期时间之间开始的事件,但我不知道如何在两个日期时间之间找到也是结束的事件。
这里是我当前的代码:
public IEnumerable<CalendarItem> GetCalendarItems(DateTime from, DateTime to) {
var events = from c in db.CalendarItems
where c.Start >= from && c.Start <= to
orderby c.Start
select c;
return events;
}
如果我使用T-SQL,我需要使用DATEADD
到Length
秒添加到Start
给一个End
日期时间,那么这将工作,但我不我认为我可以在Linq做到这一点。我能做什么?
请参阅http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.dateadd.aspx –