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 910493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:03:13+00:00 2026-05-15T17:03:13+00:00

My project has the following setup Controller -> Service (for validation) -> Repository (for

  • 0

My project has the following setup

Controller -> Service (for validation) -> Repository (for LINQ) -> dbml -> Database

Controller

''# <AcceptVerbs(HttpVerbs.Post)>  -  hiding this line so that code formatting looks proper in SO.
Function Edit(ByVal user As Domain.User, ByVal id As Integer) As ActionResult

    If ModelState.IsValid Then

        If Not String.IsNullOrEmpty(user.UserName) AndAlso _
            Not String.IsNullOrEmpty(user.WebSite) AndAlso _
            Not String.IsNullOrEmpty(user.Email) AndAlso _
            Not String.IsNullOrEmpty(user.About) AndAlso _
            Not user.Region Is Nothing AndAlso _
            Not user.BirthDate Is Nothing AndAlso _
            Not user.isProfileComplete = True Then

            user.isProfileComplete = True
            user.Reputation = user.Reputation + 10

            UserService.UpdateUser(user)

        Else
            UserService.UpdateUser(user)
        End If

        UserService.SubmitChanges()

        Return RedirectToAction("Details", "Users", New With {.id = id, .slug = user.UserName})
    Else
        Return View(user)
    End If
End Function

Service

    Public Sub UpdateUser(ByVal user As User) Implements IUserService.UpdateUser
        _UserRepository.UpdateUser(user)
    End Sub

    Public Sub SubmitChanges() Implements IUserService.SubmitChanges
        _UserRepository.SubmitChanges()
    End Sub

Repository

    Public Sub UpdateUser(ByVal user As User) Implements IUserRepository.UpdateUser
        Dim _user = (From u In dc.Users
            Where u.ID = user.ID
            Select u).Single
        _user = user
    End Sub

    Public Sub SubmitChanges() Implements IUserRepository.SubmitChanges
        dc.SubmitChanges()
    End Sub

The problem is that it’s not getting updated. I must be doing something quite stupid here. Any advice will be greatly appreciated.

  • 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-15T17:03:14+00:00Added an answer on May 15, 2026 at 5:03 pm
    Public Sub UpdateUser(ByVal user As User) Implements IUserRepository.UpdateUser 
        Dim _user = (From u In dc.Users 
            Where u.ID = user.ID 
            Select u).Single 
        _user = user 
    End Sub 
    

    In this method, you are getting the User from the database. That User instance is being tracked by Linq2Sql in terms of knowing if the properties have changed. So, after the linq statement _user is known by the data context and can be tracked. When you assign the user parameter to the object (_user = user), you lose the reference to the tracked object, and replace it with an untracked object. You can either individually update the _user variable that contains information from the database, or attempt to attach the user parameter to the data context and use that directly (dc.Users.Attach(user)). Attaching can be complex because if you don’t have the same datacontext instance than it won’t attach properly. Below is how I would do it.

    Public Sub UpdateUser(ByVal user As User) Implements IUserRepository.UpdateUser 
        Dim _user = (From u In dc.Users 
            Where u.ID = user.ID 
            Select u).Single 
        With _user
            .Name = user.Name
            .Email = user.Email
        End With
    End Sub 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am working on a project which has following setup. AVR micro-controller IDE
Assume my git repository has the following structure: /.git /Project /Project/SubProject-0 /Project/SubProject-1 /Project/SubProject-2 and
I have the following Core Data setup: Project has-many Answer Field has-many Answer Answer
The project that I'm working on has the following setup: JPA 2.0 (Hibernate 4
I have the following situation. My project has a main.scala.html file and a folder
My Application has the following structure: myproject (primary Silverlight project) myproject.Web (website for the
I'm building WPF client application. I'm following MVC pattern. The project solution has many
I have the following project. The main form has control in it. This control
My project has some unit tests. They all depend on some external service, over
I have a Python project that has the following structure: package1 class.py class2.py ...

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.