类型LINQ错误的成员访问不合法
本文关键字:访问 不合法 成员 LINQ 错误 类型 | 更新日期: 2023-09-27 18:27:08
我得到以下错误:
成员访问'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;
}
任何和所有的帮助都将不胜感激
尝试:
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();
}