Easy-to-use CRD examples (Create, Read, Delete) appear on MSDN here
There is a good link on the script page to make a test database, and I did this and easily got all the examples for CRD.
There are even handy sub-headers on the CRD page:
(Create lines) http://msdn.microsoft.com/en-us/library/hh361033.aspx#BKMK_UpdateDB
(Reading lines) http://msdn.microsoft.com/en-us/library/hh361033.aspx#BKMK_QueryData
(Delete lines) http://msdn.microsoft.com/en-us/library/hh361033.aspx#BKMK_DeleteRows
The one called BKMK_UpdateDB does not execute U in CRUD. His name says Update, but it's actually C in CRUD.
If I missed where U is displayed in CRUD on this page, just start me now and stop reading ...
Could one of the gurus here provide a little help?
To make it easier to download spam for your gurus: The code below is very similar to the MSDN webpage .
Just run the test database-create.sql script mentioned on the web page, edit the SqlDataConnection line in the code below for your server and the database name, it should work fine.
Please note that the only change I made for the request was to get only one row for the update. Now only one row is returned. It seems more important to see a simple case of a single line change. At least before showing several changes at once.
Can a guru change the last 4 lines to the recommended F # -Type-Provider method to make changes to the data returned by the request and write that they changed the line to the database?
For example, change row.TestData1 from 10 to 11 and write it in db.
Summary: Page
I have not yet had the opportunity to try new query expressions - so this is just an assumption:
query
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 (in this case) just wraps Linq-to-SQL; therefore, if the code I wrote does not work, you should take a look at some of the new .NET 4.5 Linq-to-SQL examples from C #.