Linq to SQL usage of XML
Just a reminder of something that has bitten us more than once. If you need to copy an XML value from one data object to another, use this syntax:
if( copiedPlacement != null )
{
currentPlacement.FormatXML = new XElement(copiedPlacement.FormatXML); // USUALLY CORRECT!
}
If you use the following, you’re actually doing a by-reference copy of the XElement, and changes to one will impact the other. Very subtle source of bugs if you’re not paying attention, and a real pain to find later.
if( copiedPlacement != null )
{
currentPlacement.FormatXML = copiedPlacement.FormatXML; // USUALLY WRONG!
}
