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 void Update(SqlQueryReader masterSource)
        {
            if (!masterSource.Active)
            {
                return;
            }

            var masterFieldIndex = MasterAttributeId != Guid.Empty
                ? masterSource.TryGetAttributeIndex(MasterAttributeId)
                : masterSource.TryGetAttributeIndex(MasterAttributeName);

            if (masterFieldIndex >= 0)
            {
                Slave.SetParams(SlaveParamName, masterSource.GetValue(masterFieldIndex));
            }
        }
        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);
        }