How to put the U in F# Type Provider CRUD?

前端 未结 1 1998
情书的邮戳
情书的邮戳 2021-02-15 04:21

Easy-to-follow examples of CRD (Create, Read, Delete) appear in MSDN here

There is a nice link on the page to a script to make a test database, and I did so, and easily

1条回答
  •  星月不相逢
    2021-02-15 05:11

    I haven't had a chance to try the new query expressions yet -- so this is just a guess:

    query { for row in db.Table1 do
        where (row.TestData1 <= 10)
        select row } 
        |> Seq.iter (fun row ->
            // Update the row with some new value.
            row.TestData1 <- row.TestData1 + 1)
    
    // Now, call .SubmitChanges() to execute the SQL and update the database
    try
        db.DataContext.SubmitChanges()
        printfn "Successfully updated the rows."
    with
       | exn -> printfn "Exception:\n%s" exn.Message
    

    The code on this page gives another example of how this works, albeit in C#. Basically, the F# query expression is (in this case) simply wrapping Linq-to-SQL; so if the code I posted doesn't work, you should take a look at some of the new .NET 4.5 examples of Linq-to-SQL with C#.

    0 讨论(0)
提交回复
热议问题