[英]Not sure what i am doing wrong get error: Unable to cast the type 'System.Linq.IQueryable`1' to type 'System.Linq.IQueryable`1'
[英]What am I Doing Wrong with IQueryable<T>?
我以为IQueryable <T>
是从IEnumerable <T>
派生的,所以为什么我不能像记录集合那样访问查询结果?
public bool DoLogIn(System.String strUserName, System.String strPassword)
{
if (this.IsLoggedIn)
return false;
ASRDBDataContext ASRData = new ASRDBDataContext();
IQueryable<user> CurrUser =
from usr in ASRData.users
where usr.userName == strUserName
where usr.password == strPassword
select usr;
if (CurrUser.Count() != 1)
return false;
this.CurrUserID = CurrUser[0].userID; // Error
return true;
}
返回的错误是:“无法将[]索引应用于类型'System.Linq.IQueryable <user>
'的表达式”
IEnumerable无法建立索引。 都不是IQueryable。
如果要LINQ查询的第一项,请尝试使用First() , FirstOrDefault() , Single()或SingleOrDefault()方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.