问题描述
我已经看到了很多有关如何查询数据库的示例,但是如何更新记录.以下是我编写的简单代码来检索表,但是有人可以解释我如何修改字段,说lastActivedate并在数据库上更新表
上的表格.谢谢, suday
open System open Microsoft.FSharp.Linq let connString = "Server=localhost;Database=myDb;Trusted_Connection=True;" let db = new MyDb(connString) db.Log <- System.Console.Out let res = Query.query <@ seq { for users in db.userAccounts do yield users } @> |> List.ofSeq printfn "Totla users: %d" res.Length
推荐答案
由于MyDB是System.data.linq.datacontext,因此它跟踪其加载的每个对象.只需从MyDB获取实例,在该实例上设置属性的值,然后致电mydb.submitchanges
其他推荐答案
linq(以任何.NET语言)不用于执行插入/更新/删除操作.毕竟,IT语言集成了查询.话虽如此,在您的示例中,db值应具有将修改的对象传递回数据库的方法.
问题描述
I have seen plenty of examples on how to query the database but nothing on how to update records. Below is the simple code that I wrote to retrieve a table, but can someone explain me how can I modify a field, say lastActiveDate, and update the table on the database
Thank you, suday
open System open Microsoft.FSharp.Linq let connString = "Server=localhost;Database=myDb;Trusted_Connection=True;" let db = new MyDb(connString) db.Log <- System.Console.Out let res = Query.query <@ seq { for users in db.userAccounts do yield users } @> |> List.ofSeq printfn "Totla users: %d" res.Length
推荐答案
Since MyDB is a System.Data.Linq.DataContext, it tracks each object that it loads. Simply acquire an instance from MyDB, set a property's value on that instance, and call MyDB.SubmitChanges
其他推荐答案
LInQ (in any .NET language) is not used for doing insert/update/delete operations. After all, it Language Integrated Query. That having been said, in your example the db value should have methods for passing modified objects back to the database for persistence.