How do I retrieve and set user_version in SQLite DB with EF

眉间皱痕 提交于 2019-12-21 03:43:28

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/5557622/how-do-i-retrieve-and-set-user-version-in-sqlite-db-with-ef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!