public void Execute_excutes_with_arguments()
        {
            // set-up
            ISqlQuery           sqlQuery   = A.Fake <ISqlQuery>();
            SqlText             sqlText    = A.Fake <SqlText>();
            ParameterCollection parameters = new ParameterCollection();
            const string        sql        = "select 1";

            A.CallTo(() => sqlText.Sql()).Returns(sql);
            A.CallTo(() => sqlText.Parameters).Returns(parameters);

            // call
            sqlQuery.Query <DateTime>(sqlText);

            // assert
            A.CallTo(() => sqlQuery.Query <DateTime>(sql, parameters, CommandType.Text, null)).MustHaveHappenedOnceExactly();
        }
        public void Query_executes_connection_callback()
        {
            // set-up
            ISqlQuery    sqlQuery = A.Fake <ISqlQuery>();
            SqlText      sqlText  = A.Fake <SqlText>();
            const string sql      = "select 1";

            A.CallTo(() => sqlText.Sql()).Returns(sql);
            Action <IDbConnection> callback = A.Fake <Action <IDbConnection> >();

            A.CallTo(() => sqlQuery.Query <DateTime>(sql, A <object> .Ignored, CommandType.Text, callback)).Invokes(() => callback(null));

            // call
            sqlQuery.Query <DateTime>(sqlText, callback);

            // assert
            A.CallTo(() => callback(A <IDbConnection> .Ignored)).MustHaveHappenedOnceExactly();
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a query based on the <see cref="SqlText"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sqlQuery"></param>
        /// <param name="sqlText"></param>
        /// <param name="onExecute"></param>
        /// <returns></returns>
        public static IEnumerable <T> Query <T>(this ISqlQuery sqlQuery, SqlText sqlText, Action <IDbConnection> onExecute = null)
        {
            string sql = sqlText.Sql();

            if (string.IsNullOrEmpty(sql))
            {
                return(Enumerable.Empty <T>());
            }

            return(sqlQuery.Query <T>(sql, sqlText.Parameters, CommandType.Text, onExecute));
        }
Esempio n. 4
0
 /// <summary>
 /// 获取列表
 /// </summary>
 /// <typeparam name="T1">参数类型1</typeparam>
 /// <typeparam name="T2">参数类型2</typeparam>
 /// <typeparam name="T3">参数类型3</typeparam>
 /// <typeparam name="T4">参数类型4</typeparam>
 /// <typeparam name="T5">参数类型5</typeparam>
 /// <typeparam name="T6">参数类型6</typeparam>
 /// <typeparam name="TReturn">返回类型</typeparam>
 /// <param name="sqlQuery">Sql查询对象</param>
 /// <param name="map">映射操作</param>
 /// <param name="connection">数据库连接</param>
 public static List <TReturn> ToList <T1, T2, T3, T4, T5, T6, TReturn>(this ISqlQuery sqlQuery,
                                                                       Func <T1, T2, T3, T4, T5, T6, TReturn> map, IDbConnection connection = null)
 {
     return(sqlQuery.Query((con, sql, sqlParmas) => con.Query(sql, map, sqlParmas).ToList(), connection));
 }
Esempio n. 5
0
 /// <summary>
 /// Returns dynamic query.
 /// </summary>
 /// <param name="sqlQuery"></param>
 /// <param name="sqlText"></param>
 /// <param name="onExecute"></param>
 /// <returns></returns>
 public static IEnumerable <dynamic> QueryDynamic(this ISqlQuery sqlQuery, SqlText sqlText, Action <IDbConnection> onExecute = null)
 {
     return(sqlQuery.Query <dynamic>(sqlText.Sql(), sqlText.Parameters, commandType: CommandType.Text, onExecute: onExecute));
 }
 /// <summary>
 /// 获取列表
 /// </summary>
 /// <typeparam name="T1">参数类型1</typeparam>
 /// <typeparam name="T2">参数类型2</typeparam>
 /// <typeparam name="TReturn">返回类型</typeparam>
 /// <param name="sqlQuery">Sql查询对象</param>
 /// <param name="map">映射操作</param>
 /// <param name="connection">数据库连接</param>
 public static List <TReturn> ToList <T1, T2, TReturn>(this ISqlQuery sqlQuery,
                                                       Func <T1, T2, TReturn> map, IDbConnection connection = null) =>
 sqlQuery.Query((con, sql, sqlParams) => con.Query(sql, map, sqlParams).ToList(), connection);