I’m trying to work out if something does not exist in the table. I’m telling it to see if the UserInfo contains information for user.
UserInfo Character = db.UserInfoes.SingleOrDefault(a => a.Username == user);
if (Character.Username == null || Character.Username.Length == 0)
{
//do stuff
}
But I get an error on the if statement.
Object reference not set to an instance of an object.
You need to add a test on Character to know if it’s null. If that’s the case, you’ll have the exception you mentionned.
So just do this :