예제 #1
0
        /// <summary>An OrmConnection method that selects.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="predicate">The predicate.</param>
        /// <param name="flags"></param>
        /// <returns>A List&lt;T&gt;</returns>
        public async Task <IEnumerable <T> > SelectAsync <T>(Expression <Func <T, bool> > predicate, CommandFlags flags = CommandFlags.Buffered)
        {
            TypedSelectStatement <T> select = new TypedSelectStatement <T>(DialectProvider);

            select.Where(predicate);
            return(await this.QueryAsync <T>(DialectProvider.ToSelectStatement(select.Statement, flags)));
        }
예제 #2
0
        /// <summary>An OrmConnection method that gets a scalar.</summary>
        /// <typeparam name="T">   Generic type parameter.</typeparam>
        /// <typeparam name="TKey">Type of the key.</typeparam>
        /// <param name="field">    The field.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The scalar.</returns>
        public async Task <TKey> GetScalarAsync <T, TKey>(Expression <Func <T, TKey> > field, Expression <Func <T, bool> > predicate)
        {
            //int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50);
            TypedSelectStatement <T> select = new TypedSelectStatement <T>(DialectProvider);

            select.Select(field);
            select.Where(predicate);
            return(await this.ExecuteScalarAsync <TKey>(DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None)));
        }
예제 #3
0
        /// <summary>
        ///  Execute a query that return a single value with a where predicate
        /// </summary>
        /// <example>
        ///     int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age), x => x.Age < 50);
        /// </example>
        /// <param name="field">The expression that return the single value</param>
        /// <param name="predicate">the where clause predicate</param>
        /// <typeparam name="T">The Type specifying the target table</typeparam>
        /// <typeparam name="TKey">The type of the result</typeparam>
        /// <returns></returns>
        public async Task <TKey> GetScalarAsync <T, TKey>(Expression <Func <T, TKey> > field,
                                                          Expression <Func <T, bool> > predicate)
        {
            var select = new TypedSelectStatement <T>(DialectProvider);

            select.Select(field);
            select.Where(predicate);
            return(await this.ExecuteScalarAsync <TKey>(
                       DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None)));
        }
예제 #4
0
        public void Can_select_count_with_where_Statement()
        {
            CreateModelWithFieldsOfDifferentTypes();
            using (var conn = OpenDbConnection())
            {
                var v = new TypedSelectStatement <ModelWithFieldsOfDifferentTypes>(_connectionFactory.DialectProvider);
                v.Where(x => x.Bool);

                var select = _connectionFactory.DialectProvider.ToSelectStatement(v.Statement, CommandFlags.None);

                Assert.AreEqual(5, conn.Count <ModelWithFieldsOfDifferentTypes>(x => { x.Where(q => q.Bool); }));
            }
        }