/// <summary> /// Removes an <paramref name="entity"/> using it's database-specific <paramref name="entityName"/>. /// </summary> /// <returns>Result of operation</returns> /// <exception cref="DbException">The connection-level error that occurred while opening the connection. </exception> public virtual bool Delete <TEntity>(IEntityInfo info, TEntity entity, DbActionArgs args) where TEntity : class { var parameters = new[] { PrimaryKeyParameterOf(info, entity) }; using (var command = CommandFor(DeleteCommandText(info, entity), args, parameters)) { return(command.ExecuteNonQuery() > 0); } }
/// <summary> /// Updates an <paramref name="entity"/> using it's database-specific <paramref name="entityName"/>. /// </summary> /// <returns>Result of operation</returns> /// <exception cref="DbException">The connection-level error that occurred while opening the connection. </exception> public virtual bool Update <T>(IEntityInfo info, T entity, DbActionArgs args) where T : class { var parameters = ParametersFrom(info, entity); using (var command = CommandFor(UpdateCommandText(info, entity), args, parameters)) { return(command.ExecuteNonQuery() > 0); } }
/// <summary> /// Inserts an <paramref name="entity"/> using it's database-specific <paramref name="entityName"/>. /// </summary> /// <returns>Result of operation</returns> /// <exception cref="DbException">The connection-level error that occurred while opening the connection. </exception> public virtual bool Insert <TEntity>(IEntityInfo info, TEntity entity, DbActionArgs args) where TEntity : class { var parameters = ParametersFrom(info, entity); using (var command = CommandFor(InsertCommandText(info, entity), args, parameters)) { return(command.ExecuteNonQuery() > 0); } }
/// <summary> /// Represents a command that will be executed against a database. /// </summary> /// <param name="commandText">String that represent query for command</param> /// <param name="args">Database action arguments. Connection and transaction</param> /// <param name="parameters">List of parameters</param> /// <param name="type">Type of command</param> /// <returns>Return instance of command</returns> protected internal abstract TCommand CommandFor(string commandText, DbActionArgs args, IEnumerable <TParameter> parameters, CommandType type = CommandType.StoredProcedure);
/// <summary> /// Removes an <paramref name="entities"/> using they database-specific <paramref name="entityName"/>. /// </summary> /// <returns>Result of operation</returns> /// <exception cref="DbException">The connection-level error that occurred while opening the connection. </exception> public virtual bool DeleteMany <TEntity>(IEntityInfo info, IEnumerable <TEntity> entities, DbActionArgs args) where TEntity : class { var name = DeleteCommandText(info, entities); foreach (var entity in entities) { var parameters = new[] { PrimaryKeyParameterOf(info, entity) }; using (var command = CommandFor(name, args, parameters)) { if (command.ExecuteNonQuery() <= 0) { return(false); } } } return(true); }
/// <summary> /// Inserts an <paramref name="entities"/> using they database-specific <paramref name="entityName"/>. /// </summary> /// <returns>Result of operation</returns> /// <exception cref="DbException">The connection-level error that occurred while opening the connection. </exception> public virtual bool InsertMany <TEntity>(IEntityInfo info, IEnumerable <TEntity> entities, DbActionArgs args) where TEntity : class { var name = InsertCommandText(info, entities); foreach (var entity in entities) { var parameters = ParametersFrom(info, entity); using (var command = CommandFor(name, args, parameters)) { if (command.ExecuteNonQuery() <= 0) { return(false); } } } return(true); }