public Task <TResult> MinAsync <TResult> (IDbConnection connection, string column, IDatabaseExpression whereSql, object parameter = null) { return(connection .ExecuteScalarAsync <TResult>($@"SELECT MIN({column}) FROM {this.Name} WHERE {whereSql.GetSql()}", parameter)); }
/// <summary> /// Count records with parameter /// </summary> /// <param name="connection"></param> /// <param name="sql"></param> /// <param name="parameter"></param> /// <returns></returns> public Task <long> CountAsync(IDbConnection connection, IDatabaseExpression sql, object parameter) { return(connection .ExecuteScalarAsync <long>($@"SELECT COUNT({IdName}) FROM {this.Name} WHERE {sql.GetSql()}", parameter)); }
/// <summary> /// Remove a lot of records /// </summary> /// <param name="connection"></param> /// <param name="ids"></param> public async Task RemoveRangeBufferedWithFilter (IDbConnection connection, IEnumerable <TKey> ids, IDatabaseExpression filter) { foreach (var buffer in ids.Distinct().Buffer(this.BufferSize)) { using (var transaction = connection.BeginTransaction()) { try { var param = new Tuple <TKey[]>(buffer.ToArray()); await connection.ExecuteAsync ($"DELETE FROM {this.Name} WHERE (({IdName} IN @{nameof(param.Item1)}) AND {filter.GetSql()})", param, transaction).ConfigureAwait(false); transaction.Commit(); } catch { transaction.Rollback(); } } } }
/// <summary> /// Count records /// </summary> /// <param name="connection"></param> /// <param name="sql"></param> /// <returns></returns> public long Count(IDbConnection connection, IDatabaseExpression sql) { return(connection .ExecuteScalar <long>($@"SELECT COUNT({IdName}) FROM {this.Name} WHERE {sql.GetSql()}")); }
public TableQueryable <T> Where(IDatabaseExpression sql) { this.WhereSql = sql.GetSql(); return(this); }