Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Where Have My Data Gone? Source DB doesn't get updated...

Where Have My Data Gone? Source DB doesn't get updated...

Scheduled Pinned Locked Moved LINQ
databasecsharplinqsalesquestion
1 Posts 1 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sonhospa
    wrote on last edited by
    #1

    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 PharaoDataContext

        db.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()
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups