Skip to content

Instantly share code, notes, and snippets.

Created March 17, 2012 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2065065 to your computer and use it in GitHub Desktop.
Save anonymous/2065065 to your computer and use it in GitHub Desktop.
Public Class CarRepository
Private _cars As New ChangeTracker(Of Car)()
Public Function GetCars() As IEnumerable(Of Car)
'TODO: JET/ADO code here, you would obviously do in a for/while loop
Dim dbId1 As Integer = 1
Dim make1 As String = "Ford"
Dim model1 As String = "Focus"
'TODO: create or update car objects
Dim car1 As Car
If Not _cars.IsTracking(dbId1) Then
car1 = New Car()
Else
car1 = _cars.GetItem(dbId1)
End If
car1.Make = make1
car1.Model = model1
If Not _cars.IsTracking(dbId1) Then
_cars.StartTracking(dbId1, car1)
End If
Return _cars.GetTrackedItems()
End Function
Public Sub SaveCars(ByVal cars As IEnumerable(Of Car))
'TODO: JET/ADO code here to update the item
For Each changedItem As Car In _cars.GetChangedItems().Intersect(cars)
Console.WriteLine(changedItem.Make)
Next
For Each newItem As Car In cars.Except(_cars.GetTrackedItems())
'TODO: JET/ADO code here to add the item to the DB and get its new ID
Dim newId As Integer = 5
_cars.StartTracking(newId, newItem)
Next
_cars.SetNewCheckpoint()
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment