Exemple #1
0
        public T MapRow <T>(DbCommand command, DatabaseMapRowDelegate <T> action) where T : class, new()
        {
            T item = default(T);

            using (DbConnection connection = CreateConnection())
            {
                connection.Open();
                command.Connection = connection;
                using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult))
                {
                    if (reader.Read())
                    {
                        item = new T();
                        action(item, reader, 0);
                    }
                }
            }
            return(item);
        }
Exemple #2
0
        public IEnumerable <T> MapRows <T>(DbCommand command, DatabaseMapRowDelegate <T> action) where T : class, new()
        {
            using (DbConnection connection = CreateConnection())
            {
                connection.Open();
                command.Connection = connection;
                int rowNum = 0;
                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        T item = new T();
                        action(item, reader, rowNum);
                        yield return(item);

                        rowNum++;
                    }
                }
            }
        }