Some times this type of problem comes especially when you are working with N-tier application. I got this problem when I was trying to made a change in database and I wrote
(Here Domain is a class and table in database and permission is a field of this table)
public static void UpdateXmlByDomainID(int domainID, Settings permissions)
{
MiniSitesDataContext DataContext = MSD.GetDataContext();
XElement xml = Util.GetXmlInXElement(permissions);
Domain updatedDomain = GetDomainByID(domainID);
updatedDomain.Permissionsxml = xml;
DataContext.SubmitChanges();
}
Where GetDomainByID(domainID) is a function to fetch Domain but by this method I was unable to change then I a made a change.
Hurrah! It’s working
public static void UpdateXmlByDomainID(int domainID, Settings permissions)
{
MiniSitesDataContext DataContext = MSD.GetDataContext();
XElement xml = Util.GetXmlInXElement(permissions);
Domain updatedDomain = new Domain();
updatedDomain = DataContext.Domains.Single(d => d.DomainID == domainID);
updatedDomain.Permissionsxml = xml;
DataContext.SubmitChanges();
}
Actually problem is this, LinQ put DataContext on track so this type of problems arising. In first one DataContext was not identifying that this domain is related to it but in second one we are fetching object from datacontext so when we submit changes it make change in database.
Note: This example is not related to only xml functions. Applicable any where. If your problem is still unsolved you are free to ask, may be I can help you 🙂