private PMS_USERS currUser;
private bool validateUserName()
{
    dbContext = new PmsEntities();
    var validateUser = dbContext.PMS_USERS.Where(p=> p.LOGICALREF != currUser.LOGICALREF).Where(p=> p.USERNAME == currUser.USERNAME);
    return !validateUser.Any();
}
Hello, I got an error while validating on my new user register form.
My PMS_USERS table has no record(null). I also tried checking for null control(s) for currUser.
What am I missing?
Error is :
Non static method requires a target
You should first test if currUser is null or not and your dbContext too.
if (currUser == null) return false;
if (dbContext == null) throw new Exception ("The dbContext has not been set");
Secondly, you can simplify your query like yhat :
 var validateUser = dbContext.PMS_USERS.Where(p=> p.LOGICALREF != currUser.LOGICALREF &&  p.USERNAME == currUser.USERNAME);
And then change the return statement to :
return (validateUser.FirstOrDefault() != null);
You can alternativelly use SingleOrDefault statement insead of FirstOrDefault, if you want to be sure there is only one user corresponding to your criteria.
"Non static method requires a target" means that some object inside the scope is null. 
Try checking the context and the var result values:
 dbContext = new PmsEntities();
 if (dbContext != null && currUser != null)
 {
     var validateUser = dbContext.PMS_USERS.Where(p=> p.LOGICALREF != currUser.LOGICALREF && p.USERNAME == currUser.USERNAME);
    if (validateUser !=null)
    {
       return !validateUser.Any();
    }
    else
       return null;
 }
Check it and tell us if you have the same exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With