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

The Archive Base Latest Questions

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

I have entity (LONGFORM) that is passed via AJAX to client side. This entity

  • 0

I have entity (LONGFORM) that is passed via AJAX to client side. This entity get modified on the client and it’s sent back to the server for update in the database. Here’s the server side code:

[System.Web.Services.WebMethod()]
public static LONGFORM SendDataToClient(int id)
{
    DBDataContext _db = new DBDataContext();
    LONGFORM _lf = _db.LONGFORMs.SingleOrDefault(l => l.IDLONGFORM == id);
    return _lf;
}

[System.Web.Services.WebMethod()]
public static void SaveDataFromClient(LONGFORM _lfFromClient)
{
    DBDataContext _db = new DBDataContext();
    //_db.LONGFORMs.InsertOnSubmit(_lfFromClient);
    _db.LONGFORMs.Attach(_lfFromClient);
    _db.SubmitChanges();
}

But I can’t “update” the _lfFromClient (LONGFORM) back into the DB!
If I use InsertOnSubmit the record will get inserted (despite the fact that LINQ should see that the PK field already exists in the table and thus try an update). If I use the “attach” approach nothing happens.

So, what is the correct way to update an entity that is not related to the current DataContext?

Thanks.-

EDIT: I managed to update the values in LONGFORM adding this line just before SubmitChanges():
_db.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, _lfFromClient);

Now the problems is that child entities inside _lfFromClient wont get updated 🙁

EDIT 2: Ok, I found the solution so here’s the answer in hopes it will help someone with the same problem. The trick is to also attach all the child entities because LINQ wont do it automatically. In this example FAMILYMEMBER is a child entity collection of LONGFORM that also gets update on client side. Note the “AttachAll” since LONGFORM -> FAMILYMEMBER is a one to many relation:

    [System.Web.Services.WebMethod()]
    public static void SaveData(LONGFORM _lfFromClient)
    {
        DBDataContext _db = new DBDataContext();
        _db.LONGFORMs.Attach(_lfFromClient);
        _db.FAMILYMEMBERs.AttachAll(_lfFromClient.FAMILYMEMBERs);
        _db.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, _lfFromClient);
        _db.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, _lfFromClient.FAMILYMEMBERs);
        _db.SubmitChanges();

    }
  • 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-24T23:00:16+00:00Added an answer on May 24, 2026 at 11:00 pm

    Use:

    _db.LONGFORMs.Attach(_lfFromClient, true);
    

    This way you are attaching the entity as modified.
    See Table.Attach

    If this approach gives you any problem, check out this question.

    Edit:
    If you prefer to update the entity with the POSTed data, you can try this:

    [System.Web.Services.WebMethod()]
    public static void SaveDataFromClient(LONGFORM _lfFromClient)
    {
        DBDataContext _db = new DBDataContext();
        var _lfFromDB = _db.LONGFORMs.Where(l => l.ID == _lfFromClient.ID).FirstOrDefault();
        // Update all the properties of _lfFromDB here. For example:
        _lfFromDB.Property1 = _lfFromClient.Property1;
        _lfFromDB.Property2 = _lfFromClient.Property2;
        _db.SubmitChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In entity framework I have an Entity 'Client' that was generated from a database.
I have an entity which has a property that does not get its value
I have entity class generated by E-R designer that I have modified a little.
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
In my business model I have Entity class (IPoint interface ) that has a
I have an entity that maps to an external oracle table which is one
I have an entity class that has a property with an underlying db column
I have an entity that has a state table associated with it. The state
I have an entity loaded by Hibernate (via EntityManager ): User u = em.load(User.class,
I have entity Territory class Territory { public int Id {get;set;} public string Title

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.