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

  • Home
  • SEARCH
  • 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 7490927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:47:27+00:00 2026-05-29T15:47:27+00:00

I have been struggling with getting a field value change to commit. Is there

  • 0

I have been struggling with getting a field value change to commit. Is there something obviously wrong here:

<HttpPost()>
Function Details(id As Guid?, model As RosterDetailModel) As ActionResult
If model.Action = RosterDetailModel.ActionOption.Save Then
    If model.Action = RosterDetailModel.ActionOption.Save Then
        Dim invalid = False ' initalize able to save
        'check validations
        Dim sFirstname = IIf(model.NameFirst Is Nothing, String.Empty, model.NameFirst).ToString().Trim()
        If sFirstname = String.Empty Then
            invalid = True
            ModelState.AddModelError("NameFirst", "First Name is required.")
        End If

        If invalid = False Then
            'save is ok to do
            Using db As New BCData()
                Dim userModel As New RosterDetailModel(db, id)
                'Dim userModel As New RosterDetailModel
                'userModel =
                userModel.NameFirst = sFirstname
                'db.ApplyCurrentValues(userModel)
                'db.AcceptAllChanges()
                db.SaveChanges()
                'userModel.SaveChanges(db, id, userModel)
            End Using
        End If
    End If
End If
Return View(model)
End Function

I see Entity Model Not Being Updated on SaveChanges has “The problem was I was referencing different instantiations of the Container (each manager created its own). Thus, the entity items were not attached to anything.” .. im not sure what exactly i need to change. When i tried to do a Linq query and set values directly it would tell me the field is readonly.

If invalid = False Then
    'save is ok to do
    Using db As New BCData()
    'Dim userModel As New RosterDetailModel(db, id)
    Dim userModel = From studentusers In db.studentusers _
    Where _
      studentusers.studentGuid = id _
    Select _
      studentusers.cellPhone, _
      studentusers.officePhone, _
      studentusers.phone, _
      studentusers.alternateEmail, _
      studentusers.country, _
      studentusers.zip, _
      studentusers.state, _
      studentusers.city, _
      studentusers.address2, _
      studentusers.address1, _
      studentusers.ForumeMailNotificationPreferences, _
      studentusers.magazineSubscribed, _
      studentusers.avatar, _
      studentusers.dateStudentActivated, _
      studentusers.dateDownloadOn, _
      studentusers.dateInstructorOn, _
      studentusers.instructor, _
      studentusers.ctcAdmin, _
      studentusers.download, _
      studentusers.accessLevel, _
      studentusers.datecreated, _
      studentusers.guidsignaturecookie, _
      studentusers.password, _
      studentusers.organization, _
      studentusers.email, _
      studentusers.lastname, _
      studentusers.firstname, _
      studentusers.groupGuid, _
      studentusers.studentGuid


    db.Attach(userModel)
    'Dim userModel As New RosterDetailModel
    'userModel =
    userModel.FirstOrDefault.firstname = sFirstname '**<- **** READ ONLY ???**  
                'db.ApplyCurrentValues(userModel)
    'db.AcceptAllChanges()

    db.SaveChanges()
    'userModel.SaveChanges(db, id, userModel)
End Using
  • 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-29T15:47:27+00:00Added an answer on May 29, 2026 at 3:47 pm

    Reload the userModel from the database:

    If invalid = False Then
        Using db As New BlueCardData()
            Dim userModel = (From studentuser In db.studentusers _
                             Where studentuser.studentGuid = id _
                             Select studentuser).Single()
            'original userModel from DB is attached to context now
            'change tracking will start from here
    
            userModel.firstname = sFirstname
    
            db.SaveChanges()
            'EF detects change of firstname and will create UPDATE statement
        End Using
    

    Your second code doesn’t work because you are projecting into an anonymous type and you cannot change properties of anonymous types. They are always readonly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with getting an opposite search in MySQL. Here is a
I'm using Windows 7 (IIS 7.5) and have been struggling with getting it setup
I have been struggling with getting this to work for a number of days
I have been struggling with getting this query right for hours now. I have
I have been struggling in getting Start Tls to work for my ldap server.
i have been struggling getting this to work for 2 weeks, I am trying
Have been struggling with Javascript closure for a while trying to wrap brain around
I have been struggling with the best way to make sure that the certain
I have been struggling to think of some decent uses for things like vectors
I have been struggling with this question for awhile now, and I haven't reached

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.