public override void RemoveObject(IDataObject objectToRemove)
        {
            if (PlaceObjects == null)
            {
                return;
            }
            bool completed;
            int? objectToRemoveInternalId;

            if ((objectToRemove as PlaceDataObject) == null)
            {
                _logEngine.LogError("Unable to remove null object", "The object you are trying to remove is null", "PlaceObjectsDataSet.RemoveObject", null);
                throw new PulpException("Unable to remove Null Object.");
            }

            if (objectToRemove.IsNew)
            {
                objectToRemoveInternalId = objectToRemove.InternalObjectId;
            }
            else
            {
                objectToRemoveInternalId = PlaceObjectInternalIds.ContainsKey((objectToRemove as PlaceDataObject).PrimaryKey) ? (int?)PlaceObjectInternalIds[(objectToRemove as PlaceDataObject).PrimaryKey] : null;
            }

            if (objectToRemoveInternalId != null)
            {
                PlaceDataObject value;
                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = PlaceObjects.TryRemove((int)objectToRemoveInternalId, out value);
                }

                // Reinit InternalObjectId only if the object to remove is part of the current dataset
                if (ReferenceEquals(objectToRemove.ObjectsDataSet, this._rootObjectDataSet))
                {
                    objectToRemove.InternalObjectId = null;
                }

                if (!objectToRemove.IsNew)
                {
                    int idvalue;
                    completed = false;
                    count     = 0;
                    while (!completed && count++ < 15)
                    {
                        completed = PlaceObjectInternalIds.TryRemove((objectToRemove as PlaceDataObject).PrimaryKey, out idvalue);
                    }
                }
            }
        }
        public override TDataObject GetObject <TDataObject>(TDataObject objectToGet)
        {
            int?objectToGetInternalId;

            if (objectToGet.IsNew)
            {
                objectToGetInternalId = objectToGet.InternalObjectId;
            }
            else
            {
                if ((objectToGet as PlaceDataObject) == null)
                {
                    _logEngine.LogError("Unable to get value which value is null", "The object you are trying to get doesn't have a value", "PlaceObjectsDataSet", null);
                    throw new PulpException("Unable to get an element which value is null.");
                }
                objectToGetInternalId = PlaceObjectInternalIds.ContainsKey((objectToGet as PlaceDataObject).PrimaryKey) ? (int?)PlaceObjectInternalIds[(objectToGet as PlaceDataObject).PrimaryKey] : null;
            }
            if (objectToGetInternalId != null)
            {
                return(PlaceObjects.ContainsKey((int)objectToGetInternalId) ? PlaceObjects[(int)objectToGetInternalId] as TDataObject : null);
            }

            return(null);
        }
        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 PlaceObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "PlaceObjectsDataSet", 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 = PlaceObjects.TryAdd(newInternalId, (PlaceDataObject)objectToAdd);
                }
            }

            if (!objectToAdd.IsNew && existingObject == null)
            {
                //The following if should not be necessary...
                var completed = false;
                if (PlaceObjectInternalIds.ContainsKey(((PlaceDataObject)objectToAdd).PrimaryKey))
                {
                    int value;
                    var count2 = 0;
                    while (!completed && count2++ < 15)
                    {
                        completed = PlaceObjectInternalIds.TryRemove(((PlaceDataObject)objectToAdd).PrimaryKey, out value);
                    }
                }

                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = PlaceObjectInternalIds.TryAdd(((PlaceDataObject)objectToAdd).PrimaryKey, newInternalId);
                }
            }
            // Update relations including platform as "many" side or "one" side , pk side for one to one relations
            if ((objectToAdd as PlaceDataObject) == null)
            {
                _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "PlaceDataObject", null);
                throw new PulpException("Unexpected Error: Unable to Add an object which is Null.");
            }
        }