我要做的是加载并从我的SQLite数据库中设置user_version(PRAGMA user_version)。我正在使用实体框架,但如果我不能通过它实现它,那么我需要能够在C#4.0中以其他方式实现它。
我试过了:
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();
其中DatabaseConnection是我的EF上下文,Connection是上下文中的DbConnection对象,但是我得到一个例外:
查询语法无效。近
标识符'user_version',第1行,
第8栏。
嗯......我终于明白了。我相信这是使用实体框架时最好的方法。
要设置user_version,您需要执行此操作...
this.DatabaseConnection.ExecuteStoreCommand("PRAGMA user_version = 5");
要获得user_version,您需要这样做......
long result = this.DatabaseConnection.ExecuteStoreQuery<long>("PRAGMA user_version").FirstOrDefault();
嗯......我终于明白了。我相信这是使用实体框架时最好的方法。
要设置user_version,您需要执行此操作...
this.DatabaseConnection.ExecuteStoreCommand("PRAGMA user_version = 5");
要获得user_version,您需要这样做......
long result = this.DatabaseConnection.ExecuteStoreQuery<long>("PRAGMA user_version").FirstOrDefault();