按日期过滤查询
我有以下查询:
var query =
from f in _db.Production
join g in _db.Run on f.show equals g.Production.show
select new ViewProductions {
Venuename = g.venue,
Showname = f.show,
StartDate = g.startDate,
EndDate = g.endDate
};
return View(query);
如何添加一个 where 子句来表示
从今天开始的未来 3 个月内的起始日期在哪里?
谢谢
更新
工作代码
var now = DateTime.UtcNow;
var limit = now.AddDays(90);
var query =
from f in _db.Production
join g in _db.Run on f.show equals g.Production.show
where g.endDate >= now && g.startDate <= limit
select new ViewProductions
{
Venuename = g.venue,
Showname = f.show,
StartDate = g.startDate,
EndDate = g.endDate
};
return View(query);
再次感谢您的所有帮助。
I have the following query
var query =
from f in _db.Production
join g in _db.Run on f.show equals g.Production.show
select new ViewProductions {
Venuename = g.venue,
Showname = f.show,
StartDate = g.startDate,
EndDate = g.endDate
};
return View(query);
How would i add a where clause that would say
Where start date is in the next 3 months from today?
Thanks
Update
Working code
var now = DateTime.UtcNow;
var limit = now.AddDays(90);
var query =
from f in _db.Production
join g in _db.Run on f.show equals g.Production.show
where g.endDate >= now && g.startDate <= limit
select new ViewProductions
{
Venuename = g.venue,
Showname = f.show,
StartDate = g.startDate,
EndDate = g.endDate
};
return View(query);
Thanks again for all your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您无法在 linq-to-sql 或实体框架中使用任何
DateTime.Add*
方法,因此您必须使用变量:As you can't use any
DateTime.Add*
methods in linq-to-sql or entity framework, you'll have to use variables:由于这是 Linq to Sql/Entities,因此您必须首先计算日期,然后在查询中使用它:
Since this is Linq to Sql/Entities you will have to calculate the date first, then use it in the query:
添加此行您的查询:
Add this line yo your query: