具有最短日期和加入次数的 Linq 组
我正在尝试设置 PastEvents,一个 int,并且需要一些关于如何将最终的 EventCount 转换为 int 的指导。我收到错误“无法将类型‘System.Linq.IQueryable’隐式转换为‘int’”。我正在考虑使用 Sum() 或 FirstorDefault()。任何帮助将不胜感激。
PastEvents = from ev in
(from ev in
((from e in db.ActivityEventEntities
join d in db.ActivityEventDateEntities on e.EventID equals d.EventID
where e.ActivityID == 58
group new { e, d } by new
{
e.EventID
} into g
select new
{
EventID = (Int32?)g.Key.EventID,
StartDate = (DateTime?)g.Min(p => p.d.DateValue)
}))
where
ev.StartDate > DateTime.Now
select new
{
Dummy = "x"
})
group ev by new { ev.Dummy } into g
select new
{
EventCount = (Int64?)g.Count()
}
I am trying to set PastEvents, a int, and need some guidance in how to get the final, EventCount converted to an int. I get the error "Cannot implicitly convert type 'System.Linq.IQueryable' to 'int'". I am thinking of using Sum() or FirstorDefault(). Any help would be appreciated.
PastEvents = from ev in
(from ev in
((from e in db.ActivityEventEntities
join d in db.ActivityEventDateEntities on e.EventID equals d.EventID
where e.ActivityID == 58
group new { e, d } by new
{
e.EventID
} into g
select new
{
EventID = (Int32?)g.Key.EventID,
StartDate = (DateTime?)g.Min(p => p.d.DateValue)
}))
where
ev.StartDate > DateTime.Now
select new
{
Dummy = "x"
})
group ev by new { ev.Dummy } into g
select new
{
EventCount = (Int64?)g.Count()
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)