views:

39

answers:

0
Function DeepLoadDoctors(ByVal doc As Doctor) As Doctor Implements IDoctorsService.DeepLoadDoctors

            Using _context As New referee2Entities

                doc = _context.Doctors.
                    Include("DoctorLicense").
                    Include("DoctorHome").
                    Include("DoctorHome.ContactInfoes").
                    Include("DoctorOffices").
                    Include("DoctorOffices.ContactInfoes").
                    Include("DoctorTaxonomies").Where(Function(d) d.ID = doc.ID).FirstOrDefault()

            End Using

            Return doc

        End Function

This is the function that allows me to load my object through a service.(not a wcf service)

Public Function SaveChanges(ByVal _doc As Doctor) As Boolean Implements IDoctorsService.SaveChanges
            Dim currentdoc As Doctor = GetByID(_doc.ID)
            Dim isSaved As Boolean = False

            Using _context As New referee2Entities

                _context.Doctors.Attach(_doc)

                Dim entry As ObjectStateEntry = _context.ObjectStateManager.GetObjectStateEntry(_doc)
                entry.ApplyCurrentValues(_doc)

                Try
                    _context.SaveChanges()
                    isSaved = True
                Catch ex As Exception
                    Dialog.ShowException(ex.Message, ex.ToString)

                End Try
            End Using

            Return isSaved

        End Function

This is the function that allows me to save my changed data back to the database. I have looked and looked but I have not found any scenarios that match closely with what I am doing and most scenarios assume you are using silverlight, wcf, or both. I am using neither. Just plain old WPF....This is working. I dont like it and its not pretty, but its working.

Now I have a collection object that is originally loaded in this. "ContactInfoes"(pluralization isnt quite there yet)...anyway. Each of these objects that are in the Include are being edited seperately away from the doctor object. DoctorHome is one-to-one, doctorlicense is one-to-one.

anyway, I am having mucho trouble trying to get collection saves to work....any samples or tutorials pointed to would be really helpful. This is in vb but I can read C# so id doesnt matter the language...I just need some guidance...thanks