Esempio n. 1
0
        /// <summary>
        /// Execute a query that return a single value
        /// </summary>
        /// <example>
        ///     int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age));
        /// </example>
        /// <param name="field">The expression that return the single value</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)
        {
            var select = new TypedSelectStatement <T>(DialectProvider);

            select.Select(field);
            return(await this.ExecuteScalarAsync <TKey>(
                       DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None)));
        }
        /// <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>
        /// <returns>The scalar.</returns>
        public async Task <TKey> GetScalarAsync <T, TKey>(Expression <Func <T, TKey> > field)
        {
            //int maxAgeUnder50 = db.Scalar<Person, int>(x => Sql.Max(x.Age));
            TypedSelectStatement <T> select = new TypedSelectStatement <T>(DialectProvider);

            select.Select(field);
            return(await this.ExecuteScalarAsync <TKey>(DialectProvider.ToSelectStatement(select.Statement, CommandFlags.None)));
        }