Tyr*_*ess 5 c# sqlite entity-framework-core sqlite-journal-mode
我在实体框架上使用 DBContext,使用本教程中的过程来创建数据库。
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=blog.db");
}
}
Run Code Online (Sandbox Code Playgroud)
并使用以下内容保存:
using (var context = new BloggingContext())
{
context.Add(blog);
await context.SaveChangesAsync();
}
Run Code Online (Sandbox Code Playgroud)
我将如何将日志模式设置为 WAL 之类的东西?
EF7 的 Sqlite 提供程序仅支持一小部分关闭连接字符串选项,因此您需要手动执行一些命令:
var context = new BloggingContext();
var connection = context.Database.GetDbConnection();
connection.Open();
using (var command = connection.CreateCommand())
{
command.Text= "PRAGMA journal_mode=WAL;";
command.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)
您可以将其包装在您的构造函数或工厂中。