Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sounds to me like you ought to make GetEmployees() a static method off of Employee. You shouldn't have to instantiate an employee to get a list of them. </p> <p>Also, your first example is only going to set your objEmployee to whatever comes up last in your data. While it loops through all the employees, it stops looping when it reaches the last one, which is the data you'll get returned. </p> <p>Also, does the "Employees" class refer to one employee or to many? Name it accordingly. If "Employees" represents one "Employee" then perhaps you should rename it to "Employee" and return a List from the GetEmployees method, which, as I stated above, ought to be static, so you can simply call something like "Employee.GetEmployees()". </p> <p>That being said, I'm never too fond of the architecture where you provide data access capabilities to your business object. It tends to couple the data access layer and the business object layer too tightly. </p> <p>You may want to consider creating a Data Access interface that accepts parameters for searching for employees and returns actual Employee objects as it's result. Once you do that, you would want to create an implementation of this Data Access Layer that you would then use to generate the actual instances. The advantage to this would be that you could quickly change your implementation of the Data Access Layer without having to change the business objects as well. You would program your business objects off of the Interface then, and you might be able to use dynamic assembly loading or some other method to dynamically determine the implementation of your data access. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload