-2

我想使用 linq 语法更新我的数据库。我在我的 sqlite 数据库中有这样的更新

 var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Users.db");
                using (var db = new SQLite.SQLiteConnection(dbpath))
                {
                     db.Update(new Booking()
                        {
                        });
                        db.Commit();
                        db.Dispose();
                        db.Close();
                }

我想通过简单的示例了解更新语法语法。谢谢

4

1 回答 1

1

你甚至没有尝试过update;你正在尝试insert

看看这里,你会发现你可以直接调用它。

var booking = db.Table<Booking>()
                .Where(x => x.Name == "Jack's BBQ joint")
                .FirstOrDefault();
// change something in the object
db.Update(booking);

从文档:

/// Updates all of the columns of a table using the specified object
/// except for its primary key.
/// The object is required to have a primary key.

另一种解决方案是去低级并自己创建查询:

db.Execute("update bookings set ...");
于 2014-08-18T17:05:03.060 回答