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

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

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

            if (objectToRemoveInternalId != null)
            {
                GOUserDataObject value;
                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = GOUserObjects.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 = GOUserObjectInternalIds.TryRemove((objectToRemove as GOUserDataObject).PrimaryKey, out idvalue);
                    }
                }


                // Delete the UserProfile FK Index
                if ((objectToRemove as GOUserDataObject).UserName != null)
                {
                    if (UserProfile_FKIndex.ContainsKey((System.String)(objectToRemove as GOUserDataObject).UserName) && UserProfile_FKIndex[(System.String)(objectToRemove as GOUserDataObject).UserName].Contains((int)objectToRemoveInternalId))
                    {
                        UserProfile_FKIndex[(System.String)(objectToRemove as GOUserDataObject).UserName].Remove((int)objectToRemoveInternalId);

                        if (!UserProfile_FKIndex[(System.String)(objectToRemove as GOUserDataObject).UserName].Any())
                        {
                            List <int> outvalue;
                            var        iscompleted = false;
                            var        count2      = 0;
                            while (!iscompleted && count2++ < 15)
                            {
                                iscompleted = UserProfile_FKIndex.TryRemove((System.String)(objectToRemove as GOUserDataObject).UserName, out outvalue);
                            }
                        }
                    }

                    UserProfileDataObject relatedUserProfile;
                    if ((objectToRemove as GOUserDataObject)._userProfile_NewObjectId != null)
                    {
                        relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject()
                        {
                            IsNew = true, InternalObjectId = (objectToRemove as GOUserDataObject)._userProfile_NewObjectId
                        });
                    }
                    else
                    {
                        relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject((System.String)(objectToRemove as GOUserDataObject).UserName)
                        {
                            IsNew = false
                        });
                    }

                    if (relatedUserProfile != null && this.RootObjectDataSet.NotifyChanges)
                    {
                        relatedUserProfile.NotifyPropertyChanged("GOUser", new SeenObjectCollection());
                    }
                }
            }
        }
        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 GOUserObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "GOUserObjectsDataSet", 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 = GOUserObjects.TryAdd(newInternalId, (GOUserDataObject)objectToAdd);
                }
            }

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

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


            // Update the UserProfile FK Index
            if ((objectToAdd as GOUserDataObject).UserName != null)
            {
                if (!UserProfile_FKIndex.ContainsKey((System.String)(objectToAdd as GOUserDataObject).UserName))
                {
                    var iscompleted = false;
                    var count2      = 0;
                    while (!iscompleted && count2++ < 15)
                    {
                        iscompleted = UserProfile_FKIndex.TryAdd((System.String)(objectToAdd as GOUserDataObject).UserName, new List <int>());
                    }
                }

                if (!UserProfile_FKIndex[(System.String)(objectToAdd as GOUserDataObject).UserName].Contains(newInternalId))
                {
                    UserProfile_FKIndex[(System.String)(objectToAdd as GOUserDataObject).UserName].Add(newInternalId);
                }

                UserProfileDataObject relatedUserProfile;
                if ((objectToAdd as GOUserDataObject)._userProfile_NewObjectId != null)
                {
                    relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject()
                    {
                        IsNew = true, InternalObjectId = (objectToAdd as GOUserDataObject)._userProfile_NewObjectId
                    });
                }
                else
                {
                    relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject((System.String)(objectToAdd as GOUserDataObject).UserName)
                    {
                        IsNew = false
                    });
                }

                if (relatedUserProfile != null && this.RootObjectDataSet.NotifyChanges)
                {
                    relatedUserProfile.NotifyPropertyChanged("GOUser", new SeenObjectCollection());
                }
            }
        }