title: Saving Changes to sqlite database with xamarin forms
body: <p>As a project at school we are creating a mobile app using EF core with sqlite database. 
  Following the MVVM pattern and SimpleIoc for dependency injection.</p>
  
  <p>Everything works fine untill I call on the method dbContext.SaveChanges(); I have the following classes:</p>
  
  <pre><code>public class ViewModelLocator
      {
          public ViewModelLocator()
          {
              SimpleIoc.Default.Register&lt;IUserService, UserService&gt;();
              SimpleIoc.Default.Register&lt;IUserRepository&lt;User&gt;, UserRepository&gt;();
  
              SimpleIoc.Default.Register&lt;RegistrationPageViewModel&gt;();
              SimpleIoc.Default.Register&lt;LoginPageViewModel&gt;();
          }
  
          public RegistrationPageViewModel RegistrationVM =&gt; SimpleIoc.Default.GetInstance&lt;RegistrationPageViewModel&gt;();
          public LoginPageViewModel LoginVM =&gt; SimpleIoc.Default.GetInstance&lt;LoginPageViewModel&gt;();
  
      } 
  </code></pre>
  
  <pre><code>public class DatabaseContext : DbContext
      {
          public DatabaseContext()
          {
              this.Database.EnsureCreated();
          }
          protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
          {
              optionsBuilder.UseSqlite(@"Data Source = C:\temp\SplitbillMobile.db") ;
          }
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              modelBuilder.Entity&lt;User&gt;().ToTable("Users");
          }
  
          public DbSet&lt;User&gt; Users { get; set; }
      }
  </code></pre>
  
  <p>And when I get into my UserRepository class to add a user to the database:</p>
  
  <pre><code>public bool AddUser(User user)
          {
              try
              {
                  var context = new DatabaseContext();
  
                  context.Users.Add(user);
                  context.SaveChanges();
                  return true;
              }
              catch (Exception)
              {
                  return false;
              }
          }
  </code></pre>
  
  <p>When it tries to run context.SaveChanges(); it says that my context is null.
  Or when I remove everything in my DatabaseContext class except OnConfiguring and the DbSet I receive following exception:
  <a href="https://i.stack.imgur.com/WpxH1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WpxH1.jpg" alt="exception"></a></p>
  
  <p>Any help is greatly appreciated! </p>
  
  <p>Thanks in advance.</p>