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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:55:41+00:00 2026-05-13T08:55:41+00:00

I am using Linq2Sql and trying to update a table. But no update happens

  • 0

I am using Linq2Sql and trying to update a table.

But no update happens when I try to update a column.

I have tried it with the attach statement but then I get a duplicate key error.

I am using my own entity and copying it over to the context entity as you can see.

Is that my problem?

This is my save method.

   public void SaveUser(User user)
    {

        Mylester.Domain.DataContext.User sqluser = new Mylester.Domain.DataContext.User();

        sqluser.usrID = user.ID;
        sqluser.usrEmployeeID = user.EmployeeID;
        sqluser.usrFirstName = user.FirstName;
        sqluser.usrLastName = user.LastName;
        sqluser.usrPassword = user.Password;
        sqluser.usrEmail = user.Email;
        sqluser.usrModified = user.Modified;
        sqluser.usrCreated = user.Created;
        sqluser.usrLastLoggedOn = user.LastLoggedOn;
        sqluser.usrBrowserUsed = user.BrowserUsed;
        sqluser.usrLoginOnly = user.LoginOnly;
        sqluser.usrViewedWeeklyTimesheetChanges = user.ViewedWeeklyTimesheetChanges;
        sqluser.usrActive = user.Active;

        //_dbctx.Users.Attach(sqluser);
        _dbctx.SubmitChanges();
    }

This is my test method.

[TestMethod]
public void UpdateUser()
{
    User user;

    user = _service.GetUser(1474);
    user.FirstName = "TestXXXX";
    _service.SaveUser(user);

    user = _service.GetUser(1474);
    Assert.AreEqual(user.FirstName, "TestXXXX");
}
  • 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-13T08:55:41+00:00Added an answer on May 13, 2026 at 8:55 am

    I am using my own entity and copying it over to the context entity as you can see.

    Is that my problem?

    Yes, this wrecks the DataContexts identity map (used for entity tracking). The easiest way to update is approximately:

    User user = _dbctx.Users.Single(u => u.usrID == 1474);
    user.FirstName = "TestXXXX";
    _dbctx.SubmitChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting a project from using linq2sql to use an odata source. I
I have an entity relationship setup in my mvc2 application such that each user
I have a function, Name(int, DateTime) , that I'd like to use in a
I have a series of about 30 lookup tables in my database schema, all
I am still having a issue getting over a small issue when it comes
I am going to make a smaller website in MVC.NET, mostly to learn how
This is more of a question about best pattern and practice than asking about
I am receiving an error message "Recursive call to Automation Peer API is not
I'm getting into MVC and is wonderful, however, still need to decide what dabatase
I'm coming to the end of my first MVC project, and I'm not overly

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.