One of my objects in my LinqToSql model has a field of type XElement mapped to an XML column in SQL Server.
When I do the following:
myEntity.MyXmlField.Add(new XAttribute("attribute", "value"));
...
DataContext.SubmitChanges();
The field is not updated in the database (but in other fields). I believe that the DataContext cannot track changes made inside the XElement, and therefore this field is not marked as dirty and is not updated.
Is this the correct assumption and how to fix it?
EDIT
After reading the link provided by Scrum Meister, it looks like
myEntity.MyXmlField = new XElement(myEntity.MyXmlField);
will solve the problem.
However, this solution is quite specific to XElement (how easy it is to clone), and requires a lot of processing if XElement is large.
There should be a general way to tell the DataContext that the field has changed.
source
share