コード例 #1
0
        /// <summary>
        /// Updates a record in the database.
        /// </summary>
        /// <param name="connection">Database connection.</param>
        /// <param name="entityToUpdate">The entity you wish to update.</param>
        /// <param name="statementOptions">Optional statement options (usage: statement => statement.SetTimeout().AttachToTransaction()...)</param>
        /// <returns>True if the item was updated.</returns>
        public static bool Update <TEntity>(
            this IDbConnection connection,
            TEntity entityToUpdate,
            Action <IStandardSqlStatementOptionsBuilder <TEntity> > statementOptions = null)
        {
            var options = new StandardSqlStatementOptionsBuilder <TEntity>();

            statementOptions?.Invoke(options);
            return(OrmConfiguration.GetSqlStatements <TEntity>(options.EntityMappingOverride)
                   .UpdateById(connection, entityToUpdate, options));
        }
コード例 #2
0
        /// <summary>
        /// Inserts a row into the database.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="entityToInsert"></param>
        /// <param name="statementOptions">Optional statement options (usage: statement => statement.SetTimeout().AttachToTransaction()...)</param>
        public static Task InsertAsync <TEntity>(
            this IDbConnection connection,
            TEntity entityToInsert,
            Action <IStandardSqlStatementOptionsBuilder <TEntity> > statementOptions = null)
        {
            var options = new StandardSqlStatementOptionsBuilder <TEntity>();

            statementOptions?.Invoke(options);
            return(OrmConfiguration.GetSqlStatements <TEntity>(options.EntityMappingOverride)
                   .InsertAsync(connection, entityToInsert, options));
        }
コード例 #3
0
        /// <summary>
        /// Queries the database for a set of records.
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <param name="connection"></param>
        /// <param name="statementOptions">Optional statement options (usage: statement => statement.SetTimeout().AttachToTransaction()...)</param>
        /// <returns>The record count</returns>
        public static Task <IEnumerable <TEntity> > FindAsync <TEntity>(
            this IDbConnection connection,
            Action <IRangedBatchSqlStatementOptionsOptionsBuilder <TEntity> > statementOptions = null)
        {
            var options = new RangedBatchSqlStatementOptionsOptionsBuilder <TEntity>();

            statementOptions?.Invoke(options);
            return(OrmConfiguration
                   .GetSqlStatements <TEntity>(options.EntityMappingOverride)
                   .BatchSelectAsync(connection, options));
        }
コード例 #4
0
        /// <summary>
        /// Counts all the records in a table or a range of records if a conditional clause was set up in the statement options.
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <param name="connection"></param>
        /// <param name="statementOptions">Optional statement options (usage: statement => statement.SetTimeout().AttachToTransaction()...)</param>
        /// <returns>The record count</returns>
        public static Task <int> CountAsync <TEntity>(
            this IDbConnection connection,
            Action <IConditionalSqlStatementOptionsBuilder <TEntity> > statementOptions = null)
        {
            var options = new ConditionalSqlStatementOptionsBuilder <TEntity>();

            statementOptions?.Invoke(options);
            return(OrmConfiguration
                   .GetSqlStatements <TEntity>(options.EntityMappingOverride)
                   .CountAsync(connection, options));
        }
コード例 #5
0
        /// <summary>
        /// Deletes all the records in the table or a range of records if a conditional clause was set up in the statement options.
        /// </summary>
        /// <typeparam name="TEntity">Entity Type</typeparam>
        /// <param name="connection">Database connection.</param>
        /// <param name="statementOptions">Optional statement options (usage: statement => statement.SetTimeout().AttachToTransaction()...)</param>
        /// <returns>The number of records deleted.</returns>
        public static int BulkDelete <TEntity>(
            this IDbConnection connection,
            Action <IConditionalBulkSqlStatementOptionsBuilder <TEntity> > statementOptions = null)
        {
            var options = new ConditionalBulkSqlStatementOptionsBuilder <TEntity>();

            statementOptions?.Invoke(options);
            return(OrmConfiguration
                   .GetSqlStatements <TEntity>(options.EntityMappingOverride)
                   .BulkDelete(connection, options));
        }
コード例 #6
0
 public static ISqlBuilder GetSqlBuilder <TEntity>(this IDbConnection connection, EntityMapping <TEntity> entityMappingOverride = null)
 {
     return(OrmConfiguration.GetSqlBuilder(entityMappingOverride));
 }