Where Have My Data Gone? Source DB doesn't get updated...
LINQ
1
Posts
1
Posters
4
Views
1
Watching
-
Hi all, I hope I can find someone with a deeper insight regarding LINQ here... In my sample application I add some records to a DataContext and update others. Querying the DataContext afterwards retrieves the changed / added records properly – while checking the data in the underlying database (in ServerExplorer) shows the old DB status without any changes / additions. Can someone pls tell me how I finally get the newer data written into the underlying database? Thank you for any helpful ideas! Here's the (VB) code I use:
Public Class MyMainApp
Public Shared Sub main(ByVal args() As String)
Dim db As New PharaoDataContextdb.QueryProducts() ' query all records InsertTest(db) UpdateProducts(db) db.QueryProducts() ' query again and wait for input Console.ReadLine() db.Dispose() End Sub Public Shared Sub InsertTest(ByRef db As PharaoDataContext) Dim cust As New Customer With cust .First\_Name = "Paul" .Last\_Name = "Miller" End With db.Customer.InsertOnSubmit(cust) Dim item1 As New Item With item1 .Item\_Name = "DVD" .Item\_Price = 19.75 End With db.Item.InsertOnSubmit(item1) Dim item2 As New Item With item2 .Item\_Name = "BlueRay" .Item\_Price = 29.75 End With db.Item.InsertOnSubmit(item2) ' for debugging: print changes to screen Dim mySet As System.Data.Linq.ChangeSet = db.GetChangeSet() Dim liste As Object = mySet.Inserts For Each entry As Object In liste Select Case True Case TypeOf (entry) Is Item Console.WriteLine(entry.Item\_Name) Case TypeOf (entry) Is Customer Console.WriteLine(entry.last\_name) Case Else Console.WriteLine("Objekt vom Typ '{0}'", entry.GetType.Name) End Select Next db.SubmitChanges() '<---- doesn't seem to update the DB End Sub Public Shared Sub UpdateProducts(ByRef db As PharaoDataContext) Dim query = db.Item.SingleOrDefault(Function(it) it.ItemID = 2) If query IsNot Nothing Then Console.Write("Change '{0}' to ", query.Item\_Name) query.Item\_Name = Console.ReadLine() db.SubmitChanges()