Ejemplo n.º 1
0
        public IEnumerable <T> Select <T>(String statement, ISelectable <T> traits)
        {
            var list = new List <T>();

            using (SqlCommand cmd = new SqlCommand(statement, m_connection))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    try
                    {
                        while (rdr.Read())
                        {
                            T obj = traits.ApplySelect(rdr, this, list);
                            if (obj != null)
                            {
                                list.Add(obj);
                            }
                            //possibly: yield return traits.ApplySelect(rdr);
                        }
                    }
                    finally
                    {
                        rdr.Close();
                    }
                }
            }

            return(list);
        }
Ejemplo n.º 2
0
 public IEnumerable <T> Select <T>(String statement, ISelectable <T> traits, IEnumerable <StormyParameter> parameters)
 {
     using (IDbCommand command = m_connection.CreateCommand())
     {
         command.CommandText = statement;
         TranslateParameters(command, parameters);
         using (IDataReader reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 T obj = traits.ApplySelect(reader);
                 if (obj != null)
                 {
                     yield return(obj);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public static IEnumerable <T> Hydrate <T>(this IDataReader reader, ISelectable <T> traits = null)
            where T : class, new()
        {
            var customReader = new DataReader(reader);

            while (reader.Read())
            {
                T instance = default(T);
                if (traits != null)
                {
                    instance = traits.ApplySelect(customReader, reader.GetColumns());
                }
                else
                {
                    instance = new T();
                    reader.Hydrate(instance);
                }
                yield return(instance);
            }
        }