Esempio n. 1
0
        /// <summary>
        /// 指定されたテーブルからすべてのレコードを非同期的に取得します。
        /// </summary>
        /// <typeparam name="T">テーブルにマッピングされた型</typeparam>
        /// <param name="properties">取得対象の列</param>
        /// <returns>取得したレコード</returns>
        public virtual async Task <IReadOnlyList <T> > SelectAsync <T>(Expression <Func <T, object> > properties)
        {
            var sql    = PrimitiveSql.CreateSelect(properties);
            var result = await this.Connection.QueryAsync <T>(sql, null, this.Transaction, this.Timeout).ConfigureAwait(false);

            return(result as IReadOnlyList <T>);
        }
        public static async Task <IReadOnlyList <T> > SelectAsync <T>(this IDbConnection connection, Expression <Func <T, bool> > predicate, params Expression <Func <T, object> >[] properties)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            var select = PrimitiveSql.CreateSelect(properties);

            var where = PredicateSql.From(connection.GetDbKind(), predicate);
            var builder = new StringBuilder();

            builder.AppendLine(select);
            builder.AppendLine(nameof(where));
            builder.Append($"    {where.Statement}");
            var result = await connection.QueryAsync <T>(builder.ToString(), where.Parameter).ConfigureAwait(false);

            return(result as IReadOnlyList <T>);
        }
Esempio n. 3
0
        /// <summary>
        /// 指定されたテーブルから指定の条件に一致するレコードを取得します。
        /// </summary>
        /// <typeparam name="T">テーブルにマッピングされた型</typeparam>
        /// <param name="predicate">抽出条件</param>
        /// <param name="properties">取得対象の列</param>
        /// <returns>取得したレコード</returns>
        public virtual IReadOnlyList <T> Select <T>(Expression <Func <T, bool> > predicate, Expression <Func <T, object> > properties)
        {
            var select = PrimitiveSql.CreateSelect(properties);

            var where = PredicateSql.From(this.DbKind, predicate);
            var builder = new StringBuilder();

            builder.AppendLine(select);
            builder.AppendLine(nameof(where));
            builder.Append($"    {where.Statement}");
            return(this.Connection.Query <T>(builder.ToString(), where.Parameter, this.Transaction, true, this.Timeout) as IReadOnlyList <T>);
        }
        public void 特定1列のSelect文生成()
        {
            var actual1 = PrimitiveSql.CreateSelect(typeof(Person), "Name");
            var actual2 = PrimitiveSql.CreateSelect <Person>(x => x.Name);
            var actual3 = PrimitiveSql.CreateSelect <Person>(x => new { x.Name });
            var expect  =
                @"select
    名前 as Name
from dbo.Person";

            actual1.Is(expect);
            actual2.Is(expect);
            actual3.Is(expect);
        }
        public void 全列のSelect文生成()
        {
            var actual1 = PrimitiveSql.CreateSelect(typeof(Person));
            var actual2 = PrimitiveSql.CreateSelect <Person>();
            var expect  =
                @"select
    Id as Id,
    名前 as Name,
    Age as Age,
    HasChildren as HasChildren
from dbo.Person";

            actual1.Is(expect);
            actual2.Is(expect);
        }
        public static IReadOnlyList <T> Select <T>(this IDbConnection connection, params Expression <Func <T, object> >[] properties)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            var sql = PrimitiveSql.CreateSelect(properties);

            return(connection.Query <T>(sql) as IReadOnlyList <T>);
        }
        public static async Task <IReadOnlyList <T> > SelectAsync <T>(this IDbConnection connection, params Expression <Func <T, object> >[] properties)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            var sql    = PrimitiveSql.CreateSelect(properties);
            var result = await connection.QueryAsync <T>(sql).ConfigureAwait(false);

            return(result as IReadOnlyList <T>);
        }
Esempio n. 8
0
        /// <summary>
        /// 指定されたテーブルからすべてのレコードを取得します。
        /// </summary>
        /// <typeparam name="T">テーブルにマッピングされた型</typeparam>
        /// <param name="properties">取得対象の列</param>
        /// <returns>取得したレコード</returns>
        public virtual IReadOnlyList <T> Select <T>(Expression <Func <T, object> > properties)
        {
            var sql = PrimitiveSql.CreateSelect(properties);

            return(this.Connection.Query <T>(sql, null, this.Transaction, true, this.Timeout) as IReadOnlyList <T>);
        }