I'm refactoring my code. Consider this example...
public virtual List<Student> FetchEnrollmentList(DateTime admissionDateFrom,
DateTime admissionDateTo)
{
var students = new List<Student>();
using (oconn = new OleDbConnection(OracleConnection))
{
oconn.Open();
query = "SELECT * FROM Enrollment Where AdmissionDate between @AdmissionDateFrom and @AdmissionDateTo ";
using (ocmd = new OleDbCommand(query, oconn))
{
ocmd.Parameters.Add("@AdmissionDateFrom", OleDbType.Date).Value = admissionDateFrom;
ocmd.Parameters.Add("@AdmissionDateTo", OleDbType.Date).Value = admissionDateTo;
using (odr = ocmd.ExecuteReader())
{
while (odr.Read())
students.Add(new Student { Name = odr["StudentName"].ToString() });
}
}
}
return students;
}
I just want to eliminate the From and To so I created a type like this
public virtual List<Student> FetchEnrollmentList(DateSpan admissionDate)
{
var students = new List<Student>();
using (oconn = new OleDbConnection(OracleConnection))
{
oconn.Open();
query = "SELECT * FROM Enrollment Where AdmissionDate between @AdmissionDateFrom and @AdmissionDateTo ";
using (ocmd = new OleDbCommand(query, oconn))
{
ocmd.Parameters.Add("@AdmissionDateFrom", OleDbType.Date).Value = admissionDate.Start;
ocmd.Parameters.Add("@AdmissionDateTo", OleDbType.Date).Value = admissionDate.End;
using (odr = ocmd.ExecuteReader())
{
while (odr.Read())
students.Add(new Student { Name = odr["StudentName"].ToString() });
}
}
}
return students;
}
Is it OK to have it like this? Any other ideas? thanks....