internal static void PopulateWith(this IDbCommand dbCmd, ISqlExpression expression) { dbCmd.CommandText = expression.ToSelectStatement(); //needs to evaluate SQL before setting params dbCmd.SetParameters(expression.Params); }
/// <summary> /// Returns a single scalar value using an SqlExpression. E.g: /// <para>db.Column<int>(db.From<Persion>().Select(x => Sql.Count("*")).Where(q => q.Age > 40))</para> /// </summary> public static T Scalar <T>(this IDbConnection dbConn, ISqlExpression sqlExpression) { return(dbConn.Exec(dbCmd => dbCmd.Scalar <T>(sqlExpression.ToSelectStatement(), sqlExpression.Params))); }
/// <summary> /// Returns a list of KeyValuePairs from the first 2 columns: Column 1 (Keys), Column 2 (Values) using an SqlExpression. E.g: /// <para>db.KeyValuePairsAsync<int, string>(db.From<Person>().Select(x => new { x.Id, x.LastName }).Where(x => x.Age < 50))</para> /// </summary> public static Task <List <KeyValuePair <K, V> > > KeyValuePairsAsync <K, V>(this IDbConnection dbConn, ISqlExpression query, CancellationToken token = default) { return(dbConn.Exec(dbCmd => dbCmd.KeyValuePairsAsync <K, V>(query.ToSelectStatement(), query.Params, token))); }
/// <summary> /// Returns a single Scalar value using an SqlExpression. E.g: /// <para>db.SqlScalarAsync<int>(db.From<Person>().Select(Sql.Count("*")).Where(q => q.Age < 50))</para> /// </summary> public static Task <T> SqlScalarAsync <T>(this IDbConnection dbConn, ISqlExpression sqlExpression, CancellationToken token = default) { return(dbConn.Exec(dbCmd => dbCmd.SqlScalarAsync <T>(sqlExpression.ToSelectStatement(), sqlExpression.Params, token))); }
/// <summary> /// Returns an Dictionary<K, List<V>> grouping made from the first two columns using an Sql Expression. E.g: /// <para>db.LookupAsync<int, string>(db.From<Person>().Select(x => new { x.Age, x.LastName }).Where(q => q.Age < 50))</para> /// </summary> public static Task <Dictionary <K, List <V> > > LookupAsync <K, V>(this IDbConnection dbConn, ISqlExpression sqlExpression, CancellationToken token = default) { return(dbConn.Exec(dbCmd => dbCmd.LookupAsync <K, V>(sqlExpression.ToSelectStatement(), sqlExpression.Params, token))); }
/// <summary> /// Returns a Dictionary from the first 2 columns: Column 1 (Keys), Column 2 (Values) using an SqlExpression. E.g: /// <para>db.DictionaryAsync<int, string>(db.From<Person>().Select(x => new { x.Id, x.LastName }).Where(x => x.Age < 50))</para> /// </summary> public static Task <Dictionary <K, V> > DictionaryAsync <K, V>(this IDbConnection dbConn, ISqlExpression query, CancellationToken token = default) { return(dbConn.Exec(dbCmd => dbCmd.DictionaryAsync <K, V>(query.ToSelectStatement(), query.Params, token))); }
/// <summary> /// Returns the first column in a List using an SqlExpression. E.g: /// <para>db.SqlColumn<string>(db.From<Person>().Select(x => x.LastName).Where(q => q.Age < 50))</para> /// </summary> public static List <T> SqlColumn <T>(this IDbConnection dbConn, ISqlExpression sqlExpression) { return(dbConn.Exec(dbCmd => dbCmd.SqlColumn <T>(sqlExpression.ToSelectStatement()))); }
/// <summary> /// Returns the distinct first column values in a HashSet using an SqlExpression. E.g: /// <para>db.ColumnDistinctAsync<int>(db.From<Person>().Select(x => x.Age).Where(q => q.Age < 50))</para> /// </summary> public static Task <HashSet <T> > ColumnDistinctAsync <T>(this IDbConnection dbConn, ISqlExpression query, CancellationToken token = default) { return(dbConn.Exec(dbCmd => dbCmd.ColumnDistinctAsync <T>(query.ToSelectStatement(), query.Params, token))); }
/// <summary> /// Returns an Dictionary<K, List<V>> grouping made from the first two columns using an Sql Expression. E.g: /// <para>db.Lookup<int, string>(db.From<Person>().Select(x => new { x.Age, x.LastName }).Where(q => q.Age < 50))</para> /// </summary> public static Dictionary <K, List <V> > Lookup <K, V>(this IDbConnection dbConn, ISqlExpression sqlExpression) { return(dbConn.Exec(dbCmd => dbCmd.Lookup <K, V>(sqlExpression.ToSelectStatement()))); }
/// <summary> /// Returns a Dictionary from the first 2 columns: Column 1 (Keys), Column 2 (Values) using an SqlExpression. E.g: /// <para>db.Dictionary<int, string>(db.From<Person>().Select(x => new { x.Id, x.LastName }).Where(x => x.Age < 50))</para> /// </summary> public static Dictionary <K, V> Dictionary <K, V>(this IDbConnection dbConn, ISqlExpression query) { return(dbConn.Exec(dbCmd => dbCmd.Dictionary <K, V>(query.ToSelectStatement()))); }
/// <summary> /// Returns the distinct first column values in a HashSet using an SqlExpression. E.g: /// <para>db.ColumnDistinct<int>(db.From<Persion>().Select(x => x.Age).Where(q => q.Age < 50))</para> /// </summary> public static HashSet <T> ColumnDistinct <T>(this IDbConnection dbConn, ISqlExpression query) { return(dbConn.Exec(dbCmd => dbCmd.ColumnDistinct <T>(query.ToSelectStatement()))); }
/// <summary> /// Returns the distinct first column values in a HashSet using an SqlExpression. E.g: /// <para>db.ColumnLazy<int>(db.From<Persion>().Select(x => x.LastName).Where(q => q.Age == 27))</para> /// </summary> public static IEnumerable <T> ColumnLazy <T>(this IDbConnection dbConn, ISqlExpression query) { return(dbConn.ExecLazy(dbCmd => dbCmd.ColumnLazy <T>(query.ToSelectStatement()))); }
/// <summary> /// Returns results from an arbitrary SqlExpression. E.g: /// <para>db.SqlList<Person>(db.From<Person>().Select("*").Where(q => q.Age < 50))</para> /// </summary> public static List <T> SqlList <T>(this IDbConnection dbConn, ISqlExpression sqlExpression) { return(dbConn.Exec(dbCmd => dbCmd.SqlList <T>(sqlExpression.ToSelectStatement(QueryType.Select), sqlExpression.Params))); }
/// <summary> /// Returns the distinct first column values in a HashSet using an SqlExpression. E.g: /// <para>db.Column<int>(db.From<Person>().Select(x => x.LastName).Where(q => q.Age == 27))</para> /// </summary> public static List <T> Column <T>(this IDbConnection dbConn, ISqlExpression query) { return(dbConn.Exec(dbCmd => dbCmd.Column <T>(query.ToSelectStatement(QueryType.Select), query.Params))); }
/// <summary> /// Returns results from using an SqlExpression lambda. E.g: /// <para>db.Select(db.From<Person>().Where(x => x.Age > 40))</para> /// </summary> public static List <T> Select <T>(this IDbConnection dbConn, ISqlExpression expression, object anonType = null) { return(dbConn.Exec(dbCmd => dbCmd.SqlList <T>(expression.ToSelectStatement(), anonType))); }