Exemplo n.º 1
0
        public static List <NameValue <TValue, TKey> > GetNameValueList <TValue, TKey>(DataReaderAdapter dataReader, string valueField, string keyField)
        {
            var result = new List <NameValue <TValue, TKey> >();

            if (dataReader != null)
            {
                while (dataReader.Read())
                {
                    result.Add(new NameValue <TValue, TKey>(dataReader.GetValue <TValue>(valueField), dataReader.GetValue <TKey>(keyField)));
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public static Dictionary <TKey, List <TObject> > GetGroupedItemsList <TObject, TMapper, TKey>(string keyFieldName, DataReaderAdapter dataReader)
            where TObject : new()
            where TMapper : IMapper <TObject>, new()
        {
            var mapper = new TMapper();
            List <Tuple <TKey, TObject> > list = new List <Tuple <TKey, TObject> >();

            if (dataReader != null)
            {
                while (dataReader.Read())
                {
                    TKey    key  = dataReader.GetValue <TKey>(keyFieldName);
                    TObject item = new TObject();
                    mapper.Fill(dataReader, item);
                    list.Add(new Tuple <TKey, TObject>(key, item));
                }
            }

            return(list.GroupBy(x => x.Item1)
                   .ToDictionary(x => x.Key, x => x.Select(i => i.Item2).ToList()));
        }