/// <summary> /// This <see cref="Realm"/> will start managing a <see cref="RealmObject"/> which has been created as a standalone object. /// </summary> /// <param name="obj">Must be a standalone object, <c>null</c> not allowed.</param> /// <param name="update">If <c>true</c>, and an object with the same primary key already exists, performs an update.</param> /// <exception cref="RealmInvalidTransactionException"> /// If you invoke this when there is no write <see cref="Transaction"/> active on the <see cref="Realm"/>. /// </exception> /// <exception cref="RealmObjectManagedByAnotherRealmException"> /// You can't manage an object with more than one <see cref="Realm"/>. /// </exception> /// <remarks> /// If the object is already managed by this <see cref="Realm"/>, this method does nothing. /// This method modifies the object in-place, meaning that after it has run, <c>obj</c> will be managed. /// Cyclic graphs (<c>Parent</c> has <c>Child</c> that has a <c>Parent</c>) will result in undefined behavior. /// You have to break the cycle manually and assign relationships after all object have been managed. /// </remarks> /// <returns>The passed object.</returns> public RealmObject Add(RealmObject obj, bool update = false) { ThrowIfDisposed(); AddInternal(obj, obj?.GetType(), update); return(obj); }
/// <summary> /// Removes a persistent object from this realm, effectively deleting it. /// </summary> /// <param name="obj">Must be an object persisted in this realm.</param> /// <exception cref="RealmOutsideTransactionException">If you invoke this when there is no write Transaction active on the realm.</exception> /// <exception cref="System.ArgumentNullException">If you invoke this with a standalone object.</exception> public void Remove(RealmObject obj) { if (!IsInTransaction) { throw new RealmOutsideTransactionException("Cannot remove Realm object outside write transactions"); } var tableHandle = Metadata[obj.GetType()].Table; NativeTable.remove_row(tableHandle, (RowHandle)obj.RowHandle); }
/// <summary> /// This realm will start managing a RealmObject which has been created as a standalone object. /// </summary> /// <param name="obj">Must be a standalone object, null not allowed.</param> /// <param name="update">If true, and an object with the same primary key already exists, performs an update.</param> /// <exception cref="RealmInvalidTransactionException">If you invoke this when there is no write Transaction active on the realm.</exception> /// <exception cref="RealmObjectManagedByAnotherRealmException">You can't manage an object with more than one realm</exception> /// <remarks> /// If the object is already managed by this realm, this method does nothing. /// Cyclic graphs (<c>Parent</c> has <c>Child</c> that has a <c>Parent</c>) will result in undefined behavior. You have to break the cycle manually and assign relationships after all object have been managed. /// </remarks> public void Add(RealmObject obj, bool update = false) { AddInternal(obj, obj?.GetType(), update); }