For Some reason I am getting no always null in this query I have no idea why I have debuged and I am getting no values but yet my datagrids are fine and showing users.
public Boolean VerifyPassword(string userName, string password) { //The ".FirstOrDefault()" method will return either the first matched //result or null var myUser = soccerEntities.Users .FirstOrDefault(u => u.UserName == userName && u.password == password); if (myUser == null) //User was not found { //Proceed with your login process... return false; } else //User was found { return true; //Do something to let them know that their credentials were not valid } } This is my soccer entites
private soccerEntities _soccerEntities; protected soccerEntities soccerEntities { get { if (_soccerEntities == null) { try { _soccerEntities = new soccerEntities(); } catch (Exception ex) { throw new EntityContextException("Soccer Entities Could not be created", ex); } } return _soccerEntities; } }
I am getting no always nullwhy do you expect to have always null?nullin that LINQ query then that would mean there are no elements in the collection matching that condition. Why do you expect that not to be the case? Why should a new instance ofsoccerEntitiescontain a matching element?