views:

74

answers:

1

I don't see a lot of examples on how to persist with linq/flinq- I may ultimately write a proc to dowhat I need it to, however the 1->* relationship between tableA and tableC makes that tricky. Can you persist with flinq? Is there a example published somewhere I could follow? Below is what I have tried (or rather the most logical variant of what I have tried).

Thank you in advance.

TableA (1) -> (1) TableB
TableA (1) -> (*) TableC

// add the report
let b = TableB()
b.Name <- getName()

// add the authors            
let authorSet = Data.Linq.EntitySet<TableC>()
getAuthorIds document.Authors |> Seq.iter 
(fun id -> 
     let c  = TableC()
     c.Id <- id
     authorSet.Add c)

     // add the tagged report w/ associated reoprt
     let a = TableA()
     a.field1 <- "Something"
     a.tableB = b
     a.TableC <- authorSet

     let docSet = Data.Linq.EntitySet<TableA>()
     docSet.Add doc

     db.TableA.InsertAllOnSubmit([doc])
     let cf = db.ChangeConflicts
     let cm = db.GetChangeSet
A: 

I am not sure what exactly you are trying to achieve and what fails, but at least one piece that is missing from your code is this call:

db.SubmitChanges()

In general, types TableA, TableB etc represent one row in the database, and type Table<TableA>, Table<TableB> etc represent the whole database. So if you want to add a row to a database TableA, you do something along the lines of

let rowA = TableA(Name = "Foo", Salary = 42)
db.TableA.InsertOnSubmit(rowA)
db.SubmitChanges()

You can of course have more changes in object model before you do SubmitChanges (i.e. you can and must add all relevant foreign-keyed entities with 1:1 relationship).

There is not much F#-specific here - MSDN is a great source for information on this, see e.g. http://msdn.microsoft.com/en-us/library/bb386941.aspx.

Mitya
thank you - I was having issue finding this on MSDN / web.
akaphenom