I have a problem with DataContext - it inserts existing data in my database, even without calling InsertOnSubmit. Any ideas?

Here's the code:

ApplicationDataDataContext db = new ApplicationDataDataContext();
ChangeSet c = db.GetChangeSet(); // nothing to insert
Place place = new Place();
place.Country = CountryClass.CreateObject(countryXmlString, db);
c = db.GetChangeSet(); // one Place is waiting for insert
public static class CountryClass
    {

public static Country CreateObject(string xmlCountryString, ApplicationDataDataContext db)
        {
            Country country = new Country();
            country.LoadXml(xmlCountryString);
            return country.Save(db);
        }

public static void LoadXml(this Country root, string xmlCountryString)
        {
		// loads data from XML file

            XmlDocument xmlCountry = new XmlDocument();
           
            try
            {
                xmlCountry.LoadXml(xmlCountryString);
                XmlNode rootElement = xmlCountry.DocumentElement;

                root.countryNameISOcode = rootElement.InnerText;
            }
            catch (XmlException e)
            {
                ...
            }
        }


public static Country Save(this Country root, ApplicationDataDataContext db)
        {
            Country country = (from c in db.Countries
                                 where c.countryNameISOcode == root.countryNameISOcode
                                 select c).FirstOrDefault();

					// one country found
            return country;

        }
}
This article has been dead for over six months. Start a new discussion instead.