What I am trying to do is load in and set the user_version (PRAGMA user_version) from my SQLite database. I am using entity framework, but if I can't do it through that, then I need to be able to do it some other way possible within C# 4.0.
I tried:
this.DatabaseConnection.Connection.Open();
System.Data.Common.DbCommand cmd = this.DatabaseConnection.Connection.CreateCommand();
cmd.CommandText = "PRAGMA user_version";
cmd.CommandType = System.Data.CommandType.Text;
System.Data.Common.DbDataReader reader = cmd.ExecuteReader();
where DatabaseConnection is my EF context and Connection is the DbConnection object within the context, but I get an exception:
The query syntax is not valid. Near identifier 'user_version', line 1, column 8.
Well...I eventually figured it out. I believe this is the best way to do it while using entity framework.
To set the user_version you need to do this...
this.DatabaseConnection.ExecuteStoreCommand("PRAGMA user_version = 5");
To get the user_version you need to do this...
long result = this.DatabaseConnection.ExecuteStoreQuery<long>("PRAGMA user_version").FirstOrDefault();
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