title: data reader is incompatible with the specified. does not have a corresponding column in the data reader with the same name
body: <p>I keep getting the below exception. The exception baffles me because I am not selecting <code>UserID</code>.</p>
  
  <p>I have tried changing the select to <code>SELECT *</code> but this just causes a <code>result.Count</code> of 0 regardless if the data exists or not.</p>
  
  <p>I have a dummy record in the Database called bob tob.</p>
  
  <p>I have noticed that if I hover over the Users part of <code>db.Users.SqlQuery</code>.</p>
  
  <p>The text inside is</p>
  
  <pre><code>{SELECT 
  [Extent1].[userID] AS [userID], 
  [Extent1].[userFirstName] AS [userFirstName], 
  [Extent1].[userLastName] AS [userLastName], 
  [Extent1].[userName] AS [userName], 
  [Extent1].[userEmail] AS [userEmail], 
  [Extent1].[userPassword] AS [userPassword], 
  [Extent1].[userStatus] AS [userStatus], 
  [Extent1].[userEmailVerificationStatus] AS [userEmailVerificationStatus], 
  [Extent1].[userActivationCode] AS [userActivationCode]
  FROM [dbo].[Users] AS [Extent1]}
  </code></pre>
  
  <p>I am guessing it's trying to SELECT all of the User class items regardless? If that's true Then how do I stop this? What am I missing?</p>
  
  <p>This is the exception:</p>
  
  <blockquote>
    <p>The data reader is incompatible with the specified 'UserRegistrationPasswordsModel.User'. A member of the type, 'userID', does not have a corresponding column in the data reader with the same name.   </p>
  </blockquote>
  
  <p>Below is the code that calls <code>EmailExists</code>. I added the <code>ToString()</code> falsely hoping that maybe was the issue.</p>
  
  <pre><code>#region EmailExist
  // Email already exists?
  if (Utilities.EmailExists(user.userEmail.ToString()))
  {
      // A pretty awesome way to make a custom exception
      ModelState.AddModelError("EmailExist", "Email already exists");
  
      // Bounce back
      return View(user);
  }
  #endregion
  </code></pre>
  
  <p>Below is the procedure that is supposed to check if the email exists or not. </p>
  
  <pre><code>#region EmailExists
      // Confirm if the Email exists or not
      public static bool EmailExists(string Email)
      {
          bool result = false;
          Models.UserRegistrationPasswordsEntities1 db = new Models.UserRegistrationPasswordsEntities1();
          var queryResult = db.Users.SqlQuery("SELECT userEmail FROM Users WHERE userEmail = @1;", 
                                                                            new SqlParameter("@1", Email)).FirstOrDefault();
  
          // the ternary opertor is pretty awesome
          result = queryResult.Result.GetType() == null ? false : true;
  
          return result;
      }
      #endregion
  </code></pre>
  
  <p>This is the table structure:</p>
  
  <pre><code>CREATE TABLE [dbo].[Users]
  (
      [userID]                      INT              IDENTITY (1, 1) NOT NULL,
      [userFirstName]               VARCHAR (50)     NOT NULL,
      [userLastName]                VARCHAR (50)     NOT NULL,
      [userName]                    VARCHAR (50)     NOT NULL,
      [userEmail]                   VARCHAR (50)     NOT NULL,
      [userPassword]                VARCHAR (100)    NOT NULL,
      [userStatus]                  BIT              DEFAULT ((0)) NOT NULL,
      [userEmailVerificationStatus] BIT              DEFAULT ((0)) NOT NULL,
      [userActivationCode]          UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
      [userDateOfBirth]             DATETIME         NOT NULL,
  
      PRIMARY KEY CLUSTERED ([userID] ASC)
  );
  </code></pre>
  
  <p>And this is the <code>User</code> model class:</p>
  
  <pre><code>public partial class User
  {
      public int userID { get; set; }
  
      [Display(Name = "First Name")]
      [DataType(DataType.Text)]
      [Required(AllowEmptyStrings = false, ErrorMessage ="First name required")]
      public string userFirstName { get; set; }
  
      [Display(Name = "Last Name")]
      [DataType(DataType.Text)]
      [Required(AllowEmptyStrings = false, ErrorMessage = "Last name required")]
      public string userLastName { get; set; }
  
      [Display(Name = "Username")]
      [DataType(DataType.Text)]
      [Required(AllowEmptyStrings = false, ErrorMessage = "Username required")]
      public string userName { get; set; }
  
      [Display(Name = "Email")]
      [DataType(DataType.EmailAddress)]
      [Required(AllowEmptyStrings = false, ErrorMessage = "email is required")]
      public string userEmail { get; set; }
  
      [Display(Name = "Date Of Birth")]
      [DataType(DataType.DateTime)]
      [Required(AllowEmptyStrings = false, ErrorMessage = "Date of Birth is required")]
      [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
      public DateTime userDateOfBirth { get; set;}
  
  
      [Display(Name = "Password")]
      [DataType(DataType.Password)]
      [Required(AllowEmptyStrings = false, ErrorMessage = "Password is required")]
      [MinLength(6, ErrorMessage = "Minimum of 6 characters required")]
      public string userPassword { get; set; }
  
      [Display(Name = "Confirm Password")]
      [DataType(DataType.Password)]
      [Required(AllowEmptyStrings = false, ErrorMessage = "Confirm password is required")]
      [Compare("userPassword", ErrorMessage = "Confirm password and password do not match")]
      public string userConfirmPassword { get; set; }
  
      public bool userStatus { get; set; }
      public bool userEmailVerificationStatus { get; set; }
  
      public System.Guid userActivationCode { get; set; }
  }
  </code></pre>
  
  <p>I have spent the better part of 2 hours trying to figure this out.</p>
  
  <p>Below are resources I have accessed trying to find a solution. </p>
  
  <p>Any and all help is appreciated. </p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application</a></p>
  
  <p><a href="https://forums.asp.net/t/1991176.aspx?The+data+reader+is+incompatible+with+the+specified+model" rel="nofollow noreferrer">https://forums.asp.net/t/1991176.aspx?The+data+reader+is+incompatible+with+the+specified+model</a></p>
  
  <p><a href="https://stackoverflow.com/questions/14235783/incompatible-data-reader-exception-from-ef-mapped-objects">Incompatible Data Reader Exception From EF Mapped Objects</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18791037/the-data-reader-is-incompatible-with-the-specified-entity-framework">The data reader is incompatible with the specified Entity Framework</a></p>
  
  <p><a href="https://forums.asp.net/t/1980259.aspx?I+get+this+error+The+data+reader+is+incompatible+with+the+specified+DBLaxmiTatkalModel+TblAttendence+A+member+of+the+type+AttendenceId+does+not+have+a+corresponding+column+in+the+data+reader+with+the+same+name+" rel="nofollow noreferrer">https://forums.asp.net/t/1980259.aspx?I+get+this+error+The+data+reader+is+incompatible+with+the+specified+DBLaxmiTatkalModel+TblAttendence+A+member+of+the+type+AttendenceId+does+not+have+a+corresponding+column+in+the+data+reader+with+the+same+name+</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30785019/what-can-cause-an-entitycommandexecutionexception-in-entitycommanddefinition-exe/30785020">What can cause an EntityCommandExecutionException in EntityCommandDefinition.ExecuteStoreCommands?</a></p>