Should DAL always return business objects in MVP
Posted
by
Chathuranga
on Stack Overflow
See other posts from Stack Overflow
or by Chathuranga
Published on 2014-06-02T09:04:54Z
Indexed on
2014/06/02
9:26 UTC
Read the original article
Hit count: 391
In Model View Presenter (
MVP
) pattern, it is said that ourDAL
always should returns business models. But let's say if I want to get just a number from database like the lastClientID
(the latest clients ID) which is a string, should myDAL
method returns aClientInfo
object which has about 10 other fields as well likeClientName
,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 aDataTable
fromDAL
and then in the applicationsBLL
, converts it aList
?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; } } } }
© Stack Overflow or respective owner