sqlite-net 更新方法如何工作?

How does sqlite-net update method work?

https://www.nuget.org/packages/sqlite-net

这个库的Update方法是如何将数据写入数据库的?它会重写所有列还是只更新列?

来自 SQLite for Windows Phone 8.1Update 方法的文档,它与 Windows 运行时相同:

Updates all of the columns of a table using the specified object except for its primary key.

执行的查询是从这行 LINQ 代码构建的:

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 然后将更新列,无论值是否不同。

如果您只想更新更改的列,您可以遍历所有列,比较传递给相应列的值,如果它们不同,运行 一些更新代码通过创建你自己的查询语句。