I always thought I understood how this works...but lately I have started really using interfaces and now things arent doing what I am expecting.
using entity framework, I have a service for each object that is responsible for interacting with the database and such....on my one service I am passing the collection of objects to my service as an icollection(of contactinfo) before I pass the object, the changetraker has the right states. however in my method, this is not the case and all states are set to unmodified.
Private Sub SaveExecute(ByVal param As Object)
Dim srv As Services.ContactInfoService = GetService(Of Services.IContactInfoService)()
If srv.SaveChanges(Me.ContactInfoCollection) Then
GetEvent(Of Events.EditCompletedEvent(Of ICollection(Of Model.ContactInfo))).Publish(Me.ContactInfoCollection)
End If
End Sub
Public Function SaveChanges(ByVal con As ICollection(Of ContactInfo)) As Boolean Implements IContactInfoService.SaveChanges
Using _context As New referee2Entities
For i As Integer = 0 To con.Count - 1
_context.ContactInfoes.Attach(con(i))
Next
_context.DetectChanges()
If _context.SaveChanges() > 0 Then
Return True
EnableNavigation()
End If
Return False
End Using
' Return Save()
End Function
As I said above the Me.contacInfoCollection has the right changetracking states. But Once its passed to the srv.savechanges it reverts to unmodified. I am sure its something silly I am missing...the whole EF thing can be confusing to me...