你能给我关于在我的方法中返回 linq 的源代码的解决方案吗?我的源代码是这样的:
public int GetRole(string user, string pass)
{
TAEntities db = new TAEntities();
var Hasil = from u in db.User
join r in db.Role
on u.id_Role equals r.id_Role
where u.userName == user && u.password == pass
select r.id_Role;
return Hasil;
}
我的源代码仍然是错误的。然后,我现在更新我的源代码:
public int GetRole(string user, string pass)
{
Tugas_AkhirEntities db = new Tugas_AkhirEntities();
var Hasil = from u in db.User
join r in db.Role
on u.id_Role equals r.id_Role
where u.userName == user && u.password == pass
select r.id_Role;
return Hasil.FirstOrDefault();
}
我添加了这个源代码来检查我的值是否保存在变量hasil中。
if (model.GetRole(model.UserName,model.Password) == 1)
{
return RedirectToAction("Index", "Home");
}
else
return RedirectToAction("Contact", "Home");
你能给我更多的解决方案吗?