Should DAL always return business objects in MVP
- by Chathuranga
In Model View Presenter (MVP) pattern, it is said that our DAL always should returns business models. But let's say if I want to get just a number from database like the last ClientID (the latest clients ID) which is a string, should my DAL method returns a ClientInfo object which has about 10 other fields as well like ClientName, Address etc.?
If I want to get a list of business objects from my DAL, is it acceptable to do it as follows or better to get a DataTable from DAL and then in the applications BLL, converts it a List?
public List<Employee> GetNewEmployees()
{
string selectStatement = "SELECT Employee.Emp_ID, Employee.Initials + ' ' + Employee.Surname AS Name,...";
using (SqlConnection sqlConnection = new SqlConnection(db.GetConnectionString))
{
using (SqlCommand sqlCommand = new SqlCommand(selectStatement, sqlConnection))
{
sqlConnection.Open();
using (SqlDataReader dataReader = sqlCommand.ExecuteReader())
{
List<Employee> list = new List<Employee>();
while (dataReader.Read())
{
list.Add (
new EpfEtfMaster {
EmployeeID = (int) dataReader ["emp_id"],
EmployeeName = (string) dataReader ["Name"],
AppointmentDate = (DateTime) dataReader["appointment_date"],
});
}
return list;
}
}
}
}