예제 #1
0
        public List <T> LoadObjects(IDbConnection connection)
        {
            IDataReader reader = null;

            try
            {
                List <T>   list    = new List <T>();
                IDbCommand command = connection.CreateCommand();
                command.CommandText = ResourcesHelper.GetScriptFromResources(this._scriptName);
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }
                using (reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        T sqlObject = GetObject(reader);
                        sqlObject.ParentDb = _db;
                        list.Add(sqlObject);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                throw new Exception("Loading is failed. Type: " + typeof(T).Name, ex);
            }
            finally
            {
                if (reader != null && !reader.IsClosed)
                {
                    reader.Close();
                }
            }
        }