title: How do I call SQLitePCL.Batteries.Init().?
body: <p>I am attempting to create an SQLite database for my application and have come across this error. </p>
  
  <blockquote>
    <p>System.Exception: 'You need to call SQLitePCL.raw.SetProvider().  If
    you are using a bundle package, this is done by calling
    SQLitePCL.Batteries.Init().'</p>
  </blockquote>
  
  <p>I created a simple console app the run the exact same code for creation, with no issues. The code looks like this!</p>
  
  <pre><code>using (var dataContext = new SampleDBContext())
  {
      dataContext.Accounts.Add(new Account() { AccountName = name, AccountBalance = balance });
  }
  
  
  public class SampleDBContext : DbContext
  {
      private static bool _created = false;
      public SampleDBContext()
      {
          if (!_created)
          {
              _created = true;
              Database.EnsureDeleted();
              Database.EnsureCreated();
          }
      }
      protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder)
      {
          optionbuilder.UseSqlite(@"Data Source="Source folder"\Database.db");
      }
  
      public DbSet&lt;Account&gt; Accounts { get; set; }
  }
  </code></pre>
  
  <p>Can anyone shed any light on the issue? I installed the same Nuget Packages on both projects, the only difference between the two is the Data Source and the POCO classes I used for the database.</p>
  
  <p>Thanks.</p>
  
  <p><strong>Edit</strong>
  My program currently consists of a <code>Console application</code> that references a <code>.Net Framework Class Library</code>. The <code>Console application</code> simple has a constructor that looks like this:</p>
  
  <pre><code>public Program()
  {   
      using (var db = new FinancialContext())
      {
          db.Accounts.Add(new Account() { AccountName = "RBS", AccountBalance=20 });
      }
  }
  </code></pre>
  
  <p>The Class Library has a FinancialContext as Follows:</p>
  
  <pre><code>public class FinancialContext : DbContext
  {
      public DbSet&lt;Account&gt; Accounts { get; set; }
  
      public FinancialContext()
      {
        # Database.EnsureDeleted();
          Database.EnsureCreated();
      }
  
      protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder)
      {
          optionbuilder.UseSqlite(@"Data Source="Some Source Folder"\Database.db");
      }
  }
  </code></pre>
  
  <p>The Above error is shown at the # symbol point, is there a problem with the way I am coding? I would really like to know what the issue is so I can fix it properly rather than apply a 'fix'. Also I tried the suggestion in the comments, but putting the code line <code>SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());</code> in the <code>Console Application</code> gave the error <code>SQLitePCL</code> is not in the current context, which leaves me thinking I am missing a reference?</p>