Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 950063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:30:19+00:00 2026-05-15T23:30:19+00:00

I always thought I understood how this works…but lately I have started really using

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:30:20+00:00Added an answer on May 15, 2026 at 11:30 pm

    Actually that is not possible given the way I am using services for my data operations.

    this is the way I have gotten it to work:

    Public Function Update(ByVal con As ObservableCollection(Of ContactInfo)) As Boolean Implements IContactInfoService.Update
    
    
                Using _context As New referee2Entities
                    Dim entry As ObjectStateEntry
                    For Each c As ContactInfo In con
                        If c.ID = 0 Then
                            _context.ContactInfoes.AddObject(c)
                        Else
                            _context.ContactInfoes.Attach(c)
                            entry = _context.ObjectStateManager.GetObjectStateEntry(c)
                            entry.ChangeState(EntityState.Modified)
                            entry.ApplyCurrentValues(c)
                        End If
                    Next
                    Return Save(_context)
    
                End Using
    
    
            End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always thought I understood how OOP works (and I have been using it
I always thought about this but never understood why. Simple example: public IEnumerator<Effect> GetEnumerator
I thought I understood how Open ID works, but now I'm confused... FYI, I'm
In my learning I have always learnt and understood callbacks in jQuery like this:
I understand that this may seems a very basic question, but I always thought
I always thought they were about the same thing but someone pointed me out
I always thought that parentheses improved readability, but in my textbook there is a
I always thought that *&p = p = &*p in C. I tried this
At first I thought I'm facing a very simple task. But now I realized
This is not a is math required for programming? question. I always thought that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.