コード例 #1
0
 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));
 }
コード例 #2
0
 /// <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));
 }
コード例 #3
0
        /// <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();
                    }
                }
            }
        }
コード例 #4
0
 /// <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()}"));
 }
コード例 #5
0
 public TableQueryable <T> Where(IDatabaseExpression sql)
 {
     this.WhereSql = sql.GetSql();
     return(this);
 }