예제 #1
0
        public virtual List <T> Select <T>(ORMSelect select, IDBExecutor exec) where T : new()
        {
            List <T> res = new List <T>();

            SchemaTable t = Schema.EnsureSchema(typeof(T));

            if (t != null)
            {
                SQSelectResult sr = exec.Select(select.GetQuery().Query);
                try
                {
                    while (sr.Reader.Read())
                    {
                        T item = new T();
                        BeforePopulateFromDB(item);
                        for (int i = 0; i < t.Columns.Count; i++)
                        {
                            if (!sr.Reader.IsDBNull(i))
                            {
                                if (item is IPopulateProperties)
                                {
                                    ((IPopulateProperties)item).PopulateProperty(t.Columns[i].Property.Name, GetFieldValue(sr.Reader, i, t.Columns[i]));
                                }
                                else
                                {
                                    t.Columns[i].Property.SetValue(item, GetFieldValue(sr.Reader, i, t.Columns[i]), null);
                                }
                            }
                        }
                        res.Add(item);
                    }
                }
                finally
                {
                    sr.Connection.Close();
                }
            }
            else
            {
                throw new InvalidTypeException(typeof(T));
            }

            return(res);
        }
예제 #2
0
 public SQSelectResult Execute(IDBExecutor adp)
 {
     return(adp.Select(this));
 }