I have following model corresponding to the database tables listed below.
A manager is an employee. An accountant also is an employee.
- What is the best method to get all managers in the repository? How to implement GetAllManagers() method?
- Is it proper TPT?

CODE
MyRepository.MyEmployeeRepository rep = new MyEmployeeRepository();
List<Employee> e = rep.GetAllEmployees();
public class MyEmployeeRepository
{
private string connectionStringVal;
public MyEmployeeRepository()
{
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
sqlBuilder.DataSource = ".";
sqlBuilder.InitialCatalog = "LibraryReservationSystem";
sqlBuilder.IntegratedSecurity = true;
// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SqlClient";
entityBuilder.ProviderConnectionString = sqlBuilder.ToString();
entityBuilder.Metadata = @"res://*/Test.csdl|res://*/Test.ssdl|res://*/Test.msl";
connectionStringVal = entityBuilder.ToString();
}
public List<Employee> GetAllEmployees()
{
List<Employee> employees = new List<Employee>();
using (var context = new MyEntityDataModelEDM.LibraryReservationSystemEntities1(connectionStringVal))
{
foreach (MyEntityDataModelEDM.Employee p in context.Employees)
{
employees.Add(p);
}
}
return employees;
}
public List<Manager> GetAllManagers()
{
List<Manager> managers = new List<Manager>();
using (var context = new MyEntityDataModelEDM.LibraryReservationSystemEntities1(connectionStringVal))
{
}
return managers;
}
}
EDIT
This model has drawbacks. It should consider following:
- Employee can be created without any role for him.
- One employee can have multiple roles.
Just do:
This is however a really bad way to model employees.. if an accountant changes job, you need to kill and recreate that object..
See my answer on Inheritance vs enum properties in the domain model.