【问题标题】:Setting journal mode in SQLite for Entity Framework Core code-first在 SQLite 中为 Entity Framework Core 代码优先设置日志模式
【发布时间】:2016-08-06 19:39:59
【问题描述】:

我在实体框架上使用 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 之类的模式?

【问题讨论】:

    标签: c# sqlite entity-framework-core sqlite-journal-mode


    【解决方案1】:

    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();
    }
    

    您可以将其包装在构造函数或工厂中。

    相关postother one

    【讨论】:

    • 是否必须对每个连接都执行此操作,还是只需执行一次?
    猜你喜欢
    • 2022-11-17
    • 2020-04-29
    • 1970-01-01
    • 2021-02-06
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多