我正在尝试设置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()
}
答案 0 :(得分:1)
select new
{
EventCount = (Int64?)g.Count()
}.First().EventCount;