/// <summary> /// Saves or updates the entity without its children. /// </summary> /// /// <param name="entity"> /// Entity to save or update. /// </param> /// /// <param name="idGenerator"> /// ObjectIDGenerator instance to generate IDs for objects. /// </param> /// /// <param name="options"> /// Optional options. /// </param> /// /// <returns> /// The number of affected rows. /// </returns> internal int PersistWithChildren(ref VahapYigit.Test.Models.UserRole entity, ObjectIDGenerator idGenerator, SaveOptions options = null) { int rowCount = 0; if (entity.User != null && idGenerator.HasId(entity.User, withForceId: true) == 0) { using (var db = new UserCrud(base.UserContext)) { var child = entity.User; rowCount += db.PersistWithChildren(ref child, idGenerator, options); entity.IdUser = child.Id; } } if (entity.Role != null && idGenerator.HasId(entity.Role, withForceId: true) == 0) { using (var db = new RoleCrud(base.UserContext)) { var child = entity.Role; rowCount += db.PersistWithChildren(ref child, idGenerator, options); entity.IdRole = child.Id; } } rowCount += this.Persist(ref entity, options); return(rowCount); }