Mark fields as dirty in Linq To Sql

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.

+3
source share
3

Linq-to-SQL, . , , . . :

Linq "" ? DataContext ?

+2

, , : http://connect.microsoft.com/VisualStudio/feedback/details/360433/linq-to-sql-xml-fields-dont-update

Microsoft

myEntity.MyXmlField = new XElement(myEntity.MyXmlField);

, .

+2

, XML "" - , , .

:

var field = new XElement(myEntity.MyXmlField);
field.Add(new XAttribute("attribute", "value")); 
myEntity.MyXmlField = field;
+1
source

Source: https://habr.com/ru/post/1786280/


All Articles