title: MVC Asp.NET Identity Unknown Error Occurring
body: <p>I'm working on an MVC site that is using ASP.Net Identity for the log in piece. </p>
  
  <p>There is a user table where the pk is an FK for another table (table 2). Because of this, the user cannot be deleted. As well, there are reports that are generated from table 2. This report displays the data from table 2 as long as the user name that generated the data. Another reason why deleting the user information should not be done. </p>
  
  <p>So instead of deleting the user I thought I would add a column to the user table called "Deleted". It uses a bit datatype. </p>
  
  <p>The column was added to my local copy of the database using code-first migrations. When the user logs on, this value is checked in this column is checked (0 = not deleted; 1 = deleted).</p>
  
  <p>Everything was working great on my local machine. I had no errors, code ran fine. I was able to log in with any user. I then deployed to our test server and added the "Deleted" column to the table on the test SQL server using a script.</p>
  
  <p>When I went to log in, with any user, I couldn't. I kept getting the "Error logging in.  Please re-enter credentials and try again" even though my credentials were correct.</p>
  
  <p>I deleted the files on the server and deployed again. Same thing.</p>
  
  <p>I backed out all of my changes and deployed again and was able to log in.
  So, I started adding things a piece at a time:</p>
  
  <ul>
  <li>I ran the script to add a Deleted column with a bit datatype and set
  to not null on our test SQL server </li>
  <li>Tested logging in and was able to</li>
  <li>Added public bool Deleted {get; set;} to my BL Entity and deployed to
  test</li>
  <li><p>Tried logging in and failed</p></li>
  <li><p>Removed the Deleted bool and    re-deployed</p></li>
  <li><p>Was able to log in</p></li>
  </ul>
  
  <p>I'm not understanding why this addition is causing issues. "Deleted" columns are used in other tables in the application and have not caused any issues. And because it's working fine when I run it locally I'm having a hard time determining what the issue is. </p>
  
  <p>Here is my BL Entity:</p>
  
  <pre><code>using Microsoft.AspNet.Identity.EntityFramework;
       using System;
   using System.Collections.Generic;
  namespace BlahBlah.BusinessLogic.Entities
   {
  public class User : IdentityUser
  {
      public User() : base() { }
  
      public User(string username) : base(username) { }
  
      public Guid CompanyId { get; set; }
  
      public Company Company { get; set; }
  
      public bool PrimaryAccount { get; set; }
  
      public Guid DefaultCompanyId { get; set; }
  
      public ICollection&lt;Transaction&gt; Transactions { get; set; }
  
     // public bool Deleted { get; set; }
  
  }
  }   
  </code></pre>
  
  <p>Here is a piece of my user.js code:</p>
  
  <pre><code>...
  $http(call)
              .success(function (data) {
                  userData.isAuthenticated = true;
                  userData.username = data.userName;
                  userData.role = data.role;
                  userData.bearerToken = data.access_token;
                  userData.expirationDate = new Date(data['.expires']);
  
                  setHttpAuthHeader();
  
                  if (typeof successCallback === 'function') {
                      successCallback();
                  }
              })
              .error(function (data) {
  
                  if (typeof errorCallback === 'function') {
                      if (data.error_description) {
                          errorCallback(data.error_description);
                      }
                      else {
  
                          errorCallback('Unable to contact server; please, try again later.');
                      }
                  }
              });
      };
  ... 
  </code></pre>
  
  <p>Here is a piece of my login.js code:</p>
  
  <pre><code>...
   function login(common, $location, config) {
      var getLogFn = common.logger.getLogFn;
      var log = getLogFn(controllerId);
  
      var vm = this;
  
      vm.title = 'Login';
      vm.credentials = {
          username: '',
          password: ''
      };
      vm.hideError = true;
      vm.errorMessage = 'xx.';
  
      vm.login = function login() {
          vm.hideError = true;
          common.$broadcast(config.events.spinnerToggle, { show: true });
          common.user.authenticate(vm.credentials.username, vm.credentials.password, onSuccessfullLogin, onFailedLogin);
      };
  ...
  function onFailedLogin(error) {
          common.$broadcast(config.events.spinnerToggle, { show: false });
          console.log('error ' + error);
          vm.hideError = false;
      }
  ...  
  </code></pre>
  
  <p>Any ideas as to what is going on or how I can find out what is going on? Thanks for your time!  </p>
  
  <p><strong>UPDATE</strong>
  I shouldn't have gotten too excited. After performing some testing in the application I thought I would test the reports. Everything was working beautifully up until then. When I viewed a report I got the following error:</p>
  
  <blockquote>
    <p>The model backing the 'BabDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database</p>
  </blockquote>
  
  <p>The reports are using SSRS. If I ran the script to create the column AND update the _Migrations table I'm not understanding why I'm getting this error. The stack trace points to the last line. I've read suggestions but where I need to add some code to the OnModelCreating method but I'm not sure if that's the way to go. There have been other deploys done by others prior to me so I'm missing something.  </p>
  
  <pre><code>public class AbaDbContext : IdentityDbContext&lt;User&gt;, IDbContext
  {
      public const int UnknownCTId = 1;
      private IEncryptionService _encryptionService;
      private static Dictionary&lt;Guid, string&gt; _cipherCache = new Dictionary&lt;Guid,string&gt;();
  
      public BabDbContext()
          : base("BabDbContext")
      {
          ((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized += new ObjectMaterializedEventHandler(ObjectMaterialized);
  </code></pre>