Checking for Linq Variables
i m making wcf service for login. my code for accesssing db data using linq is :
var result = from detail in dc.tbl_User_Masters where detail.User_Type_Id == 2
select new UserVerification
{
Uname = detail.User_Login_Name,
Password = detail.User_Pwd
};
where UserVerification is class which has Uname and Password properties stored..now how to check that variabl开发者_Go百科e that if they are null then we'll not allow login...i dont know how to do that with linq..
You probably need to filter on the user/password you're trying to authenticate:
var givenUname = "robertpaulson";
var givenPassword = "bob";
var result = (
from detail in dc.tbl_User_Masters
where detail.User_Type_Id == 2
where detail.User_Login_Name == givenUname && detail.User_Pwd == givenPassword
select detail
).SingleOrDefault();
Now result
will either be null
or have the details for the authenticated user.
You don't have to do that in Linq. You have completed your linq part.
You may use
if (result == null) {//code for stoping the login process}
or
if (result.UserName == null) {//code for stoping the login process}
精彩评论