【发布时间】:2018-02-21 16:40:24
【问题描述】:
我有一个存储过程sp_ValidateUser,它返回两列UserID 和RoleID。
我创建的函数导入使用了以下设置:
MVC 代码:
[HttpPost]
[AllowAnonymous]
public ActionResult Index(tblUser user)
{
SchoolDBEntities usersEntities = new SchoolDBEntities();
int? userId = usersEntities.fnValidateUser(user.Username, user.Password).FirstOrDefault(); //Check if correct username and password
string message = string.Empty;
if (userId.RoleID == 1) //returns error
{
//Redirect to URL
}
return View(user);
}
如何从sp_ValidateUser_Result 的返回集合中同时检索RoleID 和UserID?
【问题讨论】:
-
旁注:您应该不为您的存储过程使用
sp_前缀。微软有reserved that prefix for its own use (see Naming Stored Procedures),你确实会在未来某个时候冒着名称冲突的风险。 It's also bad for your stored procedure performance。最好只是简单地避免sp_并使用其他东西作为前缀 - 或者根本不使用前缀! -
看看
usersEntities.fnValidateUser(user.Username, user.Password).FirstOrDefault()的结果就知道了。这不是int?。返回的类型会提示您下一步该做什么。
标签: asp.net-mvc entity-framework