我想获取用户表里的用户ID。然后再把ID传给Session。
部分源代码如下:
public bool Logon(LogOnModel model)
{
int? valid = ((from u in storeDB.Users.Where
(user => user.UserName == model.UserName && user.UserPWD == model.UserPWD)
select u).ToList()).Count;
HttpContext.Current.Session["UserName"] = model.UserName;
IQueryable<int> id =from u in storeDB.Users.Where
(u => u.UserName ==model.UserName)
select UserID;
HttpContext.Current.Session["UserID"] =id;
if (valid > 0)
{
return true;
}
else
{
return false;
}
}
但是提取id 获取失败。
var id =storeDB.Users.SingleOrDefault(u => u.UserName ==model.UserName).UserID;
这样写试试
valid 是不是等于 0?