• 无法将类型System.Collections.Generic.IEnumerable<int>隐式转换为int
  • 发布于 1天前
  • 18 热度
    1 评论

我在用Linq执行SQL语句时,系统报:无法将类型“System.Collections.Generic.IEnumerable<int>”隐式转换为“int”的错误。大家帮忙看一下是啥问题。

string sql = string.Format("select COUNT(ID) as Total from [Student] where StudentID={0} and FormStatus='Submitted' ", userID);
int rowCount = dataContext.ExecuteQuery<int>(sql);
我想返回某个学生总共有几门选修课,用count()函数计算,但是上面的代码会报错!

用户评论
  • 独走人海
  • 你这个执行查询的SQL应该返回的是条查询记录结果,就是select count(ID) form table 如果执行SQL查询出来的数比如是个10,你应该把10读取出来再转换成int
  • 2025/6/21 12:03:00 [ 0 ] [ 0 ] 回复