成员访问在类型LINQ错误上不合法

时间:2014-10-20 17:31:49

标签: c# linq

我收到以下错误:

  

会员访问' System.Nullable 1[System.Int32] pointsGained' of 'SuperGoalSQLDataBase.TriviaCode' not legal on type 'System.Collections.Generic.List 1 [SuperGoalSQLDataBase.TriviaCode]。

这是我的代码:

 public List<User> GetLeaderBoard()
       {
           SuperGoalDataClassesDataContext myDB = new SuperGoalDataClassesDataContext();
           var userResults = (from u in myDB.Users
                              where u.firstName != null && u.lastName != null
                              orderby (FillUserCodes(u).Sum(co => co.pointsGained ?? 0))
                             select u).Take(100);
           List<User> users = new List<User>();
           foreach (var usr in userResults)
           {
               if(usr.myPoints > 0)
                    users.Add(usr);
           }
           return users;
       }

任何和所有帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

尝试:

public List<User> GetLeaderBoard()
   {
       SuperGoalDataClassesDataContext myDB = new SuperGoalDataClassesDataContext();
       return myDB.Users.Where(u=> u.firstName != null && u.lastName != null).AsEnumerable()
                         .OrderBy(u=> FillUserCodes(u).Sum(co => co.pointsGained ?? 0))
                         .Take(100).Where(u=> u.mypoints > 0).ToList();
   }