2013-08-30 60 views
0

嗨我想获得这个linq查询的计数。我使用实体框架与存储库模式。 可能通过queryUserWalls.ToList()。Count() 得到结果,我认为这是低效的。 任何身体都可以帮忙。用连接和联合计数查询

var queryUserWalls = (from participation in _eventParticipationRepository.GetAll() 
         join eve in _eventRepository.GetAll() on participation.EventId equals eve.Id 
         join userWall in _userWallRepository.GetAll() on participation.EventId equals userWall.EventId 
         where participation.UserId == userId 
         select userWall.Id) 

       .Union(from userWall in _userWallRepository.GetAll() 
         select userWall.Id); 
+0

为什么不能直接执行'.Count()'? (no'.ToList()') – xanatos

+0

为什么你不能调用'queryUserWalls.Count()'? – MarcinJuraszek

回答

1

由于它强制执行查询,因此省略ToList。你想使用Queryable.Count,而不是Enumerable.Count。然后,它将在服务器上执行。