/// <summary> /// Inserts an entity into the database. /// </summary> /// <param name="entity">The entity to be inserted</param> /// <returns>The number of rows inserted</returns> public int Insert(TEntity entity) { if (entity == null) { throw new ArgumentException("Entity must not be null."); } var properties = BuildPropertyList(InsertFields); var parameters = BuildParameterList(InsertFields, entity); var connection = GetConnection(); int result; try { var sql = _queryGenerator.Insert(Table, properties, Key); result = connection.Execute(sql, parameters); } finally { if (!_useProvidedConnection) { connection.Dispose(); } } return(result); }
public virtual void Add(T entity) { ExecuteQuery(_queryGenerator.Insert(entity)); }