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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:54:54+00:00 2026-05-11T11:54:54+00:00

Some background: I have an database that I want to use linq-to-sql to update

  • 0

Some background: I have an database that I want to use linq-to-sql to update through a C# application. One of the columns in this table has an XML datatype.

Every other column in that table (that isn’t of an XML datatype) updates perfectly fine, but when I went to make changes to the XML field, the program executes (seemingly) correctly, but the field always retains its original value after I run SubmitChanges().

I looked around the internet and found a few posts on Microsoft Connect diagnosing similar problems and finally stumbled on the solution here:

To force XML field update this won’t do:

XElement tmp = MyLinqObject.XmlField; MyLinqObject.XmlField = null; MyLinqObject.XmlField = tmp; 

Instead of that to force LINQ to update XML column assign a cloned object:

MyLinqObject.XmlField = new XElement (MyLinqObject.XmlField); 

I can confirm that this does indeed seem to work, but I’m not exactly sure why. My only guess is that the XmlField Property has some sort of unique identifier on the heap and that by making a clone, you’ve assigned it a new unique identifier. When Linq then generates the query, it doesn’t even attempt to see if the field has been updated, since it has a new id, it simply write the value to the database. But, I’m simply speculating and hope that someone else can provide a better understanding of what is going on behind the scenes.

EDIT: To address Jon’s post, the reason for the issue (as it is explained on the MS Connect site) is that ‘the XML field does not update because Linq-to-SQL doesn’t handle the XElement.Changed event’.

For my implementation, the code that works ends up looking something like this:

MyXElementProperty.SetElementValue('Author', author);  MyXElementProperty = new XElement(MyXElementProperty); 

For reference (to anyone else that finds this question), the following also works:

MyXElementProperty = new XElement(MyXElementProperty);  MyXElementProperty.SetElementValue('Author', author); 
  • 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. 2026-05-11T11:54:54+00:00Added an answer on May 11, 2026 at 11:54 am

    When you make it a new XElement, you’re making a different object. It’s possible that to detect ‘staleness’ it’s using reference equality, which would obviously treat this as a new value.

    At what point are you actually making changes to the element? I would expect LINQ to SQL to have a cached copy of the original value, and then compare that with the new value. If it’s taking that ‘cached copy’ by just copying the reference, then whatever you do to that object, it will always think the two are equal. If instead you create a new element, and then change that, then the old object will still have the old value, so the comparison will understand that you’ve made changes. Does that make sense?

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

Sidebar

Related Questions

We have an application that downloads some files in the background. Our application pops
First some background: VB.NET 2005 Application that accesses a MS-SQL back-end, using multiple Web
Background: I have one Access database (.mdb) file, with half a dozen tables in
Background: I have a PostgreSQL (v8.3) database that is heavily optimized for OLTP. I
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
Some background: In Germany (at least) invoice numbers have to follow certain rules: The
As usual, some background information first: Database A (Access database) - Holds a table
Background: Some time ago, I built a system for recording and categorizing application crashes
I'm having some serious issues with a WinForm application that I'm working on. Currently,
Essentially I want to embed some XHTML in an XML document that must validate

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.