예제 #1
0
        public int Count()
        {
            var count = 0;
            var sql   = SqlQueryBuilder.Build(DataContext, Def);

            sql.AddAttribute("&Id", SqlQuerySummaryFunction.Count);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                reader.Open();
                if (reader.Read())
                {
                    if (!reader.IsDbNull(0))
                    {
                        count = reader.GetInt32(0);
                    }
                }
                reader.Close();
            }
            return(count);
        }
예제 #2
0
        public T Sum <T>(string attrDefName)
        {
            T   result = default(T);
            var sql    = SqlQueryBuilder.Build(DataContext, Def);

            sql.AddAttribute(attrDefName, SqlQuerySummaryFunction.Sum);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                reader.Open();
                if (reader.Read())
                {
                    if (!reader.IsDbNull(0))
                    {
                        var v = reader.GetValue(0);

                        v.TryParse(out result);
                    }
                }
                reader.Close();
            }
            return(result);
        }