Setting journal mode in SQLite for Entity Framework Core code-first

c# entity-framework-core sqlite sqlite-journal-mode

Question

I'm using DBContext on Entity Framework, using a process like in this tutorial to create the DB.

public class BloggingContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlite("Filename=blog.db");
    }
}

and saving using something like:

using (var context = new BloggingContext())
{
    context.Add(blog);
    await context.SaveChangesAsync();
}

How would I go about setting the Journal Mode to something like WAL?

1
5
7/18/2018 12:33:50 PM

Popular Answer

The Sqlite provider for EF7 support only a small subset off connection string option, therefore you will need to execute some commands manually :

var context = new BloggingContext();
var connection = context.Database.GetDbConnection();
connection.Open();
using (var command = connection.CreateCommand())
{
    command.Text= "PRAGMA journal_mode=WAL;";
    command.ExecuteNonQuery();
}

You could wrap that in your constructor or in a factory.

Related post and other one.

4
5/23/2017 10:28:13 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow