开发者

How to update a table in database using LINQ in F#?

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 u开发者_开发百科sers 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜