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

前端 未结 1 2115
一生所求
一生所求 2021-02-15 04:23

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:18

    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)
提交回复
热议问题