0
var loggedInHours = db.LoginLogs.Where(l => l.UserId == u.Id && l.UserSessionStop != null)
                                                                     .Sum(ls=> ls.UserSessionStart.Subtract(ls.UserSessionStop.Value).Hours)

I am trying to calculate Total LoggedIn Hours using this linq query.. But its giving me this error "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS." I don't know whats wrong with it..plz help

Abhishek
  • 173
  • 1
  • 2
  • 6
  • http://stackoverflow.com/questions/1904314/only-one-expression-can-be-specified-in-the-select-list-when-the-subquery-is-not – mshsayem Apr 04 '12 at 08:31

1 Answers1

2

Try if this works:

var loggedInHours = db.LoginLogs.Where(l => l.UserId == u.Id && l.UserSessionStop != null)
                      .Select(l=> new { 
                                         StartTime = l.UserSessionStart,  
                                         EndTime = l.UserSessionStop
                                      })
                     .ToList()
                     .Sum(c=> c.StartTime - c.EndTime);

btw, Is UserSessionStop nullable? If yes, then what will be the value to be subtracted?

mshsayem
  • 17,557
  • 11
  • 61
  • 69