public double SumAsDouble(string attrDefName)
        {
            double count = 0;
            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))
                    {
                        if (reader.Reader.GetFieldType(0) == typeof(double))
                        {
                            count = reader.GetDouble(0);
                        }
                        else if (reader.Reader.GetFieldType(0) == typeof(decimal))
                        {
                            count = (double)reader.GetDecimal(0);
                        }
                    }
                }
                reader.Close();
            }
            return(count);
        }
        public List <T> All <T>(string attrDefName)
        {
            var list = new List <T>();
            var sql  = SqlQueryBuilder.Build(DataContext, Def);

            sql.AddAttribute(attrDefName);

            using (var reader = new SqlQueryReader(DataContext, sql))
            {
                reader.Open();
                while (reader.Read())
                {
                    if (!reader.IsDbNull(0))
                    {
                        T   item;
                        var v = reader.GetValue(0);
                        list.Add(v.TryParse(out item) ? item : default(T));
                    }
                    else
                    {
                        list.Add(default(T));
                    }
                }
                reader.Close();
            }
            return(list);
        }
        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);
        }
        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);
        }