private BatchEditDto Fetch(IDataReader data)
 {
     var batchEdit = new BatchEditDto();
     using (var dr = new SafeDataReader(data))
     {
         if (dr.Read())
         {
             batchEdit.Num = dr.GetInt32("batch_num");
             batchEdit.Date = !dr.IsDBNull("batch_date") ? dr.GetSmartDate("batch_date", true) : null;
             batchEdit.PayDate = !dr.IsDBNull("pay_date") ? dr.GetSmartDate("pay_date", true) : null;
             batchEdit.Amount = (Decimal?)dr.GetValue("batch_amount");
             batchEdit.JobNum = (int?)dr.GetValue("job_num");
             batchEdit.Description = !dr.IsDBNull("batch_dscr") ? dr.GetString("batch_dscr") : null;
             batchEdit.Updated = !dr.IsDBNull("updated") ? dr.GetSmartDate("updated", true) : null;
             batchEdit.ThankYou1 = !dr.IsDBNull("thank_you_1") ? dr.GetString("thank_you_1") : null;
             batchEdit.StudyTopic = !dr.IsDBNull("study_topic") ? dr.GetString("study_topic") : null;
             batchEdit.ThankYou2 = !dr.IsDBNull("thank_you_2") ? dr.GetString("thank_you_2") : null;
             batchEdit.MarketingResearchMessage = !dr.IsDBNull("marketing_research_message") ? dr.GetString("marketing_research_message") : null;
         }
         FetchChildren(dr);
     }
     return batchEdit;
 }
 /// <summary>
 /// Updates in the database all changes made to the BatchEdit object.
 /// </summary>
 /// <param name="batchEdit">The Batch Edit DTO.</param>
 /// <returns>The updated <see cref="BatchEditDto"/>.</returns>
 public BatchEditDto Update(BatchEditDto batchEdit)
 {
     using (var ctx = ConnectionManager<SqlConnection>.GetManager("MyDatabase"))
     {
         using (var cmd = new SqlCommand("dbo.UpdateBatchEdit", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@batch_num", batchEdit.Num).DbType = DbType.Int32;
             cmd.Parameters.AddWithValue("@batch_date", batchEdit.Date.DBValue).DbType = DbType.DateTime;
             cmd.Parameters.AddWithValue("@pay_date", batchEdit.PayDate.DBValue).DbType = DbType.DateTime;
             cmd.Parameters.AddWithValue("@batch_amount", batchEdit.Amount == null ? (object)DBNull.Value : batchEdit.Amount.Value).DbType = DbType.Decimal;
             cmd.Parameters.AddWithValue("@job_num", batchEdit.JobNum == null ? (object)DBNull.Value : batchEdit.JobNum.Value).DbType = DbType.Int32;
             cmd.Parameters.AddWithValue("@batch_dscr", batchEdit.Description == null ? (object)DBNull.Value : batchEdit.Description).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@thank_you_1", batchEdit.ThankYou1 == null ? (object)DBNull.Value : batchEdit.ThankYou1).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@study_topic", batchEdit.StudyTopic == null ? (object)DBNull.Value : batchEdit.StudyTopic).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@thank_you_2", batchEdit.ThankYou2 == null ? (object)DBNull.Value : batchEdit.ThankYou2).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@marketing_research_message", batchEdit.MarketingResearchMessage == null ? (object)DBNull.Value : batchEdit.MarketingResearchMessage).DbType = DbType.String;
             var rowsAffected = cmd.ExecuteNonQuery();
             if (rowsAffected == 0)
                 throw new DataNotFoundException("BatchEdit");
         }
     }
     return batchEdit;
 }
 /// <summary>
 /// Inserts a new BatchEdit object in the database.
 /// </summary>
 /// <param name="batchEdit">The Batch Edit DTO.</param>
 /// <returns>The new <see cref="BatchEditDto"/>.</returns>
 public BatchEditDto Insert(BatchEditDto batchEdit)
 {
     using (var ctx = ConnectionManager<SqlConnection>.GetManager("MyDatabase"))
     {
         using (var cmd = new SqlCommand("dbo.AddBatchEdit", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@batch_num", batchEdit.Num).Direction = ParameterDirection.Output;
             cmd.Parameters.AddWithValue("@batch_date", batchEdit.Date.DBValue).DbType = DbType.DateTime;
             cmd.Parameters.AddWithValue("@pay_date", batchEdit.PayDate.DBValue).DbType = DbType.DateTime;
             cmd.Parameters.AddWithValue("@batch_amount", batchEdit.Amount == null ? (object)DBNull.Value : batchEdit.Amount.Value).DbType = DbType.Decimal;
             cmd.Parameters.AddWithValue("@job_num", batchEdit.JobNum == null ? (object)DBNull.Value : batchEdit.JobNum.Value).DbType = DbType.Int32;
             cmd.Parameters.AddWithValue("@batch_dscr", batchEdit.Description == null ? (object)DBNull.Value : batchEdit.Description).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@thank_you_1", batchEdit.ThankYou1 == null ? (object)DBNull.Value : batchEdit.ThankYou1).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@study_topic", batchEdit.StudyTopic == null ? (object)DBNull.Value : batchEdit.StudyTopic).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@thank_you_2", batchEdit.ThankYou2 == null ? (object)DBNull.Value : batchEdit.ThankYou2).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@marketing_research_message", batchEdit.MarketingResearchMessage == null ? (object)DBNull.Value : batchEdit.MarketingResearchMessage).DbType = DbType.String;
             cmd.ExecuteNonQuery();
             batchEdit.Num = (int)cmd.Parameters["@batch_num"].Value;
         }
     }
     return batchEdit;
 }