0

我有一种方法来验证我的用户,但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);
    }
}
4

1 回答 1

3

您缺少 IsActive 上的范围变量 (c)。做这个:

var user = GetSingleRow(c => c.Email.Equals(username) && c.Password.Equals(password) && c.IsActive);
于 2012-11-10T22:24:07.490 回答