"ERROR: Only one expression can be specified in the select list" Linq To Sql

Go To StackoverFlow.com

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

2012-04-04 08:26
by Abhishek
http://stackoverflow.com/questions/1904314/only-one-expression-can-be-specified-in-the-select-list-when-the-subquery-is-no - mshsayem 2012-04-04 08:31


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?

2012-04-04 08:42
by mshsayem
thanks mshsayem. - Abhishek 2012-04-04 09:03
Ads