我正在嘗試使用EF7處理我的SQLite數據庫。當我使用System.Data.SQLite.SQLiteConnectionStringBuilder()初始化連接字符串時,如下所示:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    var connectionStringBuilder = new SQLiteConnectionStringBuilder() { DataSource = Constants.DataDBPath };
    connectionStringBuilder.DefaultTimeout = 5000;
    connectionStringBuilder.SyncMode = SynchronizationModes.Off;
    connectionStringBuilder.JournalMode = SQLiteJournalModeEnum.Memory;
    connectionStringBuilder.PageSize = 65536;
    connectionStringBuilder.CacheSize = 16777216;
    connectionStringBuilder.FailIfMissing = false;
    connectionStringBuilder.ReadOnly = false;
    connectionStringBuilder.Version = 3;
    var connectionString = connectionStringBuilder.ToString();
    var connection = new SQLiteConnection() { ConnectionString = connectionString };
    optionsBuilder.UseSqlite(connection);
}

我收到以下錯誤:

指定演員表無效。

在命令上:

isExists = context.Blocks.Where(w => w.Hash == hash).Any();

當我使用Microsoft.Data.Sqlite.SqliteConnectionStringBuilder()初始化連接字符串時,如下所示:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    var connectionStringBuilder = new SqliteConnectionStringBuilder() { DataSource = Constants.DataDBPath  };
    var connectionString = connectionStringBuilder.ToString();
    var connection = new SQLiteConnection() { ConnectionString = connectionString };
    optionsBuilder.UseSqlite(connection);
}

我沒有任何錯誤。一切正常但更新速度很慢。我不知道如何配置數據庫以提高性能,就像我之前的連接字符串生成器一樣。當我嘗試手動添加諸如“synchronous = Off; pooling = True;”之類的參數時到連接字符串,我得到一個例外,無法識別參數。

請幫忙。

更新:

我試過了:

using (var context = new DataDBContext())
{
    var connection = context.Database.GetDbConnection();
    connection.Open();
    var command = connection.CreateCommand();
    command.CommandText = "PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF; PRAGMA count_changes=OFF; PRAGMA temp_store=OFF; PRAGMA page_size=65536; PRAGMA cache_size=-16777216;";
    command.ExecuteNonQuery();
}

但它沒有幫助。

熱門答案

您必須將Microsoft提供的提供程序與EF Core一起使用,並且它僅支持System.Data.Sqlite中的一小部分連接字符串選項。您可以通過pragma語句設置許多選項



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因