我在 Entity Framework 上使用 DBContext,使用类似 in this tutorial 的过程创建数据库。
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=blog.db");
}
}
并使用类似的方式保存:
using (var context = new BloggingContext())
{
context.Add(blog);
await context.SaveChangesAsync();
}
我如何将日志模式设置为 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();
}
您可以将其包装在您的构造函数或工厂中。
关于c# - 在 Entity Framework Core 代码优先的 SQLite 中设置日志模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36636861/