3

接受此代码的语法:

public async Task UpdateLocationAsync(SOs_Locations locations)
{
    var db = new SQLiteAsyncConnection(SQLitePath);
    await db.UpdateAsync(locations);
}

...但我不明白 SQLite 引擎在简单地传递类实例时如何知道要更新哪个记录。SQLite 或 SQLite-net 引擎是否会偷看 ID 值并在幕后执行(在 SQLese 中):

UPDATE SOs_Locations
Set Bla = Bla, etc.
WHERE ID = locations.Id

?

4

1 回答 1

3

这正是它的作用。您可以在此处查看方法的来源:

var q = string.Format ("update \"{0}\" set {1} where {2} = ? ", map.TableName, string.Join (",", (from c in cols
        select "\"" + c.Name + "\" = ? ").ToArray ()), pk.Name);

当然,如果您需要更多控制权,您可以随时执行自己的 SQL:

db.ExecuteAsync("UPDATE SOs_Locations Set Bla = ?, WHERE ID = ?", bla, id);
于 2012-12-23T07:48:46.550 回答