public override void AddObject(IDataObject objectToAdd, bool replaceIfExists) { var existingObject = GetObject(objectToAdd); if (!replaceIfExists && existingObject != null) { throw new PulpException("Object already exists"); } int newInternalId; if (existingObject != null) { //RemoveObject(existingObject); if (existingObject.InternalObjectId == null) { _logEngine.LogError("Error while trying to Add Object to the CountryObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "CountryObjectsDataSet", null); throw new PulpException("Error while trying to add an object to the dataset without InternalObjectId"); } newInternalId = (int)existingObject.InternalObjectId; objectToAdd.InternalObjectId = newInternalId; existingObject.CopyValuesFrom(objectToAdd, false); } else { newInternalId = GetNextNewInternalObjectId(); objectToAdd.InternalObjectId = newInternalId; var completed = false; var count = 0; while (!completed && count++ < 15) { completed = CountryObjects.TryAdd(newInternalId, (CountryDataObject)objectToAdd); } } if (!objectToAdd.IsNew && existingObject == null) { //The following if should not be necessary... var completed = false; if (CountryObjectInternalIds.ContainsKey(((CountryDataObject)objectToAdd).PrimaryKey)) { int value; var count2 = 0; while (!completed && count2++ < 15) { completed = CountryObjectInternalIds.TryRemove(((CountryDataObject)objectToAdd).PrimaryKey, out value); } } completed = false; var count = 0; while (!completed && count++ < 15) { completed = CountryObjectInternalIds.TryAdd(((CountryDataObject)objectToAdd).PrimaryKey, newInternalId); } } // Update relations including platform as "many" side or "one" side , pk side for one to one relations if ((objectToAdd as CountryDataObject) == null) { _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "CountryDataObject", null); throw new PulpException("Unexpected Error: Unable to Add an object which is Null."); } }