Esempio n. 1
0
 /// <summary>
 /// Map a row of data to a Customer object.
 /// </summary>
 /// <remarks>This method should not call Next() on the 
 /// DataReader; it should only extract the values of the current row.
 /// </remarks>
 /// <param name="dataReader">The IDataReader to map</param>
 /// <param name="rowNum">the number of the current row.</param>
 /// <returns>A Customer object.</returns>
 public object MapRow(IDataReader dataReader, int rowNum)
 {
     Customer customer = new Customer();
     customer.Address = dataReader.GetString(0);
     customer.City = dataReader.GetString(1);
     customer.CompanyName = dataReader.GetString(2);
     customer.ContactName = dataReader.GetString(3);
     customer.ContactTitle = dataReader.GetString(4);
     customer.Country = dataReader.GetString(5);
     customer.Fax = dataReader.GetString(6);
     customer.Id = dataReader.GetString(7);
     customer.Phone = dataReader.GetString(8);
     customer.PostalCode = dataReader.GetString(9);
     customer.Region = dataReader.GetString(10);
     return customer;
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the customers.
        /// </summary>
        /// <returns>A list of customers</returns>


        /// <summary>
        /// Gets the customers using a row mapper delegate.
        /// </summary>
        /// <remarks>Note that a NullMappingDataReader is used to convert
        /// DbNull values to simple defaults (i.e. empty string)
        /// when getting data from the DataReader.  You can provide AdoTemplate
        /// with your own version or not use a dataReader 'wrapper' entirely.
        /// </remarks>
        /// <returns>A list of customers</returns>
        public virtual IList<Customer> GetCustomersWithDelegate()
        {
            return AdoTemplate.QueryWithRowMapperDelegate<Customer>(CommandType.Text, cmdText,
                        delegate(IDataReader dataReader, int rowNum)
                            {
                                Customer customer = new Customer();
                                customer.Address = dataReader.GetString(0);
                                customer.City = dataReader.GetString(1);
                                customer.CompanyName = dataReader.GetString(2);
                                customer.ContactName = dataReader.GetString(3);
                                customer.ContactTitle = dataReader.GetString(4);
                                customer.Country = dataReader.GetString(5);
                                customer.Fax = dataReader.GetString(6);
                                customer.Id = dataReader.GetString(7);
                                customer.Phone = dataReader.GetString(8);
                                customer.PostalCode = dataReader.GetString(9);
                                customer.Region = dataReader.GetString(10);
                                return customer;
                            });
        }