我正在使用Mono,SQLite,Dapper和Dapper Extensions。我可以從數據庫中讀取但是Insert不起作用。我正在使用Mono Driver for sqlite。
錯誤不是很有用,至少對我而言。任何幫助都感激不盡。
錯誤:
SQLite error
near ".": syntax error
at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn, System.String strSql, Mono.Data.Sqlite.SqliteStatement previous, UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0
at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0
測試代碼:
public void can_add_a_service_record()
{
var provider = new Provider { Name = "Hotmail" };
int id = providerData.Insert(provider);
Assert.AreEqual("Hotmail", providerData.Get(id).Name);
}
插入代碼如下。
public virtual int Insert (TEntity entity)
{
var connection = SqlHelper.GetConnection();
int id = connection.Insert<TEntity>(entity);
connection.Close();
return id;
}
謝謝
Chirdeep
對我來說,這看起來像是Dapper Extensions問題,而不是Dapper問題。特別是,我看不到實現的Sqlite方言: https : //github.com/tmsmith/Dapper-Extensions/tree/master/DapperExtensions/Sql 。
要解決我建議你提交Dapper Extensions項目的補丁(它與Dapper完全分開)或在Dappe上使用不同的包裝器,或者在沒有包裝器的情況下使用Dapper。
例如,以下應該有效:
var id = cnn.Query<int>("insert cars values(@name); select last_insert_rowid()",
new {name = "bmw"});