Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有最小日期和加入计数的Linq组_Linq - Fatal编程技术网

具有最小日期和加入计数的Linq组

具有最小日期和加入计数的Linq组,linq,Linq,我正在尝试设置PasteEvents,一个int,并且需要一些关于如何将最终的EventCount转换为int的指导。我得到错误“无法隐式地将类型'System.Linq.IQueryable'转换为'int'。我正在考虑使用Sum()或FirstorDefault()。任何帮助都将不胜感激 PastEvents = from ev in (from ev in ((from e in db.ActivityEventEntities

我正在尝试设置PasteEvents,一个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()
                                     }

我最终不得不使用FirstorDefault,但这很有效。谢谢
select new
{
    EventCount = (Int64?)g.Count()
}.First().EventCount;