title: Getting NullReferenceException IRepository.Insert Call DNN Evoq 8.2
body: <p>I'm working on a custom module for our site. The process flow is as follows.</p>
  
  <ul>
  <li>Customer hits a specific page</li>
  <li>Page detects if customer is authenticated
  
  <ul>
  <li>No - forces login/register</li>
  <li>Yes - Continues</li>
  </ul></li>
  <li>Verifies customer data</li>
  <li>Retrieves token and ttl from sister site</li>
  <li>Stores data in db table</li>
  <li>Redirects customer to sister site using token to login</li>
  </ul>
  
  <p>I have the following class:</p>
  
  <pre><code>[TableName("AutoRegister_Data")]
  [PrimaryKey("rId", AutoIncrement = true)]
  [Scope("ModuleId")]
  [Cacheable("AutoRegister_Data", CacheItemPriority.Normal, 20)]
  public class RegisterData
  {
      public int rId { get; set; }
      public int UserID { get; set; }
      public string Email { get; set; }
      public string LastToken { get; set; }
      public DateTime LastUpdate { get; set; }
  }
  </code></pre>
  
  <p>Using the following code to update the database </p>
  
  <pre><code>using (IDataContext db = DataContext.Instance())
  {
      var repo = db.GetRepository&lt;RegisterData&gt;();
      var user = repo.Find($"WHERE UserID = {currentUser.UserID}");
  
      db.BeginTransaction();
  
      try
      {
          if (!user.Any())
          {
              repo.Insert(dataRecord);
              db.Commit();
          }
          else
          {
              string query = string.Empty;
              if (token != null)
              {
                  query = $"SET [LastUpdateDate] = \'{DateTime.Now}\', [LastToken] = \'{token}\' WHERE [UserID] = {currentUser.UserID}";
              }
              repo.Update(query);
          }
      }
      catch (Exception ex)
      {
          db.RollbackTransaction();
          Exceptions.ProcessModuleLoadException(this, ex);
      }
  }
  </code></pre>
  
  <p>The dataRecord is of the class RegisterData.</p>
  
  <p>I get an Object reference not set to an instance of an object error.</p>
  
  <p>If I take the update out of a transaction block the table gets updated with correct data but the error still occurs. </p>
  
  <p>Any guidance would be most appreciated.</p>
  
  <p>~Scott</p>