public static decimal CalcTotalRate(this UserMaster user) { using (SECURITY_DBEntities context = new SECURITY_DBEntities()) { List <byte?> ratings = context.Ratings.Where(r => r.DriverId == user.UserID).Select(r => r.RateValue).ToList(); var TotalRate = ((decimal)ratings.Sum <byte?>(l => l.Value) / ratings.Count); TotalRate = Math.Round(TotalRate, 2); return(TotalRate); } }