Ejemplo n.º 1
0
        internal IList List(Type type, IConnectinContext cc, Region region)
        {
            TimeWatch.________________________________________________________("Peanut->SQL to list");
            System.Type itemstype = System.Type.GetType("System.Collections.Generic.List`1");
            itemstype = itemstype.MakeGenericType(type);
            IList result;

            if (region == null)
            {
                region = new Region(0, 99999999);
            }
            if (region.Size > DBContext.DefaultListMaxSize)
            {
                result = (IList)Activator.CreateInstance(itemstype, DBContext.DefaultListMaxSize);
            }
            else
            {
                result = (IList)Activator.CreateInstance(itemstype, region.Size);
            }
            Mappings.CommandReader cr = Mappings.CommandReader.GetReader(mBaseSql, type);
            int     index             = 0;
            Command cmd = GetCommand();

            TimeWatch.________________________________________________________("Peanut->DataReader to list");
            using (IDataReader reader = cc.ExecuteReader(cmd))
            {
                TimeWatch.________________________________________________________("Peanut->Read Data");
                while (reader.Read())
                {
                    if (index >= region.Start)
                    {
                        object item = Activator.CreateInstance(type);
                        cr.ReaderToObject(reader, item);
                        result.Add(item);
                        if (result.Count >= region.Size)
                        {
                            cmd.DbCommand.Cancel();
                            reader.Dispose();
                            break;
                        }
                    }
                    index++;
                }
                TimeWatch.________________________________________________________();
            }
            TimeWatch.________________________________________________________();
            TimeWatch.________________________________________________________();
            return(result);
        }