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

Filed under:
|
|
|
|
  1. 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.?

  2. 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;
                }
            }
        }
    }
    

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET