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?
This database provider allows Entity Framework Core to be used with SQLite. The provider is maintained as part of the Entity Framework Core project.
Create SQLite Database from code with EF Core MigrationsGenerate new EF Core migration files by running the command dotnet ef migrations add InitialCreate from the project root folder (where the WebApi. csproj file is located), these migrations will create the database and tables for the . NET Core API.
To install EF Core, you install the package for the EF Core database provider(s) you want to target. This tutorial uses SQLite because it runs on all platforms that . NET Core supports.
Code-First is mainly useful in Domain Driven Design. In the Code-First approach, you focus on the domain of your application and start creating classes for your domain entity rather than design your database first and then create the classes which match your database design.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With