我有一种方法来验证我的用户,但user = null
即使我的表中有记录,它也会返回。
public bool AuthenticateUser(string username, string password)
{
var user = GetSingleRow(c => c.Email.Equals(username) && c.Password.Equals(password) && IsActive);
if(user !=null && user.Id > 0)
{
// my statements
}
}
类和方法实现:
public partial class UserAccount :IRepository<UserAccount>
{
private static readonly MeriRanchiDataContext Context;
public UserAccount GetSingleRow(Func<UserAccount, bool> criteria)
{
return Context.UserAccounts.Where(criteria).SingleOrDefault();
//tried this also: return Context.UserAccounts.SingleOrDefault(criteria);
}
}