[英]Linq Query Unable to Return Expected Result
我正在將wcf服務消費到Angular JS應用程序中。 但我收到了預期的結果。 我懷疑Linq Query或Angular Js Application上的問題。 這是我要實現的目標,如果用戶名和密碼錯誤,則該方法應返回false並開始計算嘗試次數。 如果用戶輸入了4次錯誤的用戶名或密碼,則帳戶將被鎖定。 否則,如果使用4次輸入正確的用戶名或密碼,則方法應返回true並將嘗試計數重置為零。
這是我的界面。
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
//BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "/AuthenticateUser")]
bool AuthenticateUser(UserLogin userLogin );
這是方法的實現..
public bool AuthenticateUser(UserLogin userLogin)
{
using (HalifaxDatabaseEntities db = new HalifaxDatabaseEntities())
{
var attamp = from X in db.tblUsers
where X.Username==userLogin.Username&& X.Password== userLogin.Password
select X.RetryAttempts!=4;
if (attamp!=null )
{
return true;
}
else
{
return false;
}
}
}
返回集合(如Select
或Where
)的linq查詢永遠不會返回null
。 只有返回單個結果的查詢(例如First
或Single
)才可以。
盡管還不清楚如何更改RetryAttempts
,但更好的方法可能是:
// this will return a collection will only one result - true or false
var attamp = from X in db.tblUsers
where X.Username==userLogin.Username&& X.Password== userLogin.Password
select X.RetryAttempts!=4;
//.Single() will give you the value of the one and only result - either true or false
return attamp.Single();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.