Reputation: 173
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
Upvotes: 0
Views: 361
Reputation: 18018
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?
Upvotes: 2