F# Linq Add New Rows To Sql Server
I am learning LINQ with F# 3.0. I want to know how to re-write my old code to use new LINQ features in F# 3.0 For example, I have created a simple data table in SQL Server 2008 R2,
Solution 1:
You can use InsertOnSubmit and InsertAllOnSubmit for nice, statically typed record insertion. Something like:
let newRecords =
[for i in [0 .. 1] ->
new Table1(Id=(i + 1), TestData1=(i * 10), TestData2=( decimal i ) * 5.0M, Name="Testing" + (i + 1).ToString())]
db.Table1.InsertAllOnSubmit(newRecords)
db.SubmitChanges()
Also see http://msdn.microsoft.com/en-us/library/hh361033(v=vs.110).aspx and search within the page for "InsertOnSubmit" (in fact, the example there is made for your Table1 demo table).
Post a Comment for "F# Linq Add New Rows To Sql Server"