Reputation: 93
I'm still confusing in what should be coded in data layer and in business layer. because some of method can implemented in both of theme. for example I want the Employs between two date or somethings like this. so should I do that in BL or in AL.
namespace DataLayer
{
public class EmployeRepository : IEmployeRepository
{
public List<Employe> GetList()
{
using (ADON3Entities db = new ADON3Entities())
{
return db.Employes.ToList();
}
}
public List<Employe> GetEmploysBetweenDates(DateTime start, DateTime end)
{
using (ADON3Entities db = new ADON3Entities())
{
return db.Employes.Where(em => em.NaissEmploye >= start && em.NaissEmploye <= end).ToList();
}
}
}
}
or I should doing that like this:
namespace BusinessLayer
{
public static class EmployeServices
{
static IEmployeRepository repository;
static EmployeServices()
{
repository = new EmployeRepository();
}
public static List<Employe> GetList()
{
return repository.GetList();
}
public static List<Employe> GetEmploysBetweenDates(DateTime start, DateTime end)
{
return repository.GetList().Where(em => em.NaissEmploye >= start && em.NaissEmploye <= end).ToList();
}
}
}
And thank in advanced for any help or reference to understand tree layer architecture!
Upvotes: 0
Views: 550
Reputation: 164
The rule of thumb is, if it is just a query and all it is doing is talking to the database, it belongs in the datalayer (this is your case). But if there are business rules around what employees you are retrieving, that should go into the business layer. Please read this for more details.
Upvotes: 0
Reputation: 61379
In many cases, especially with large datasets; you want that kind of method to be in the data layer. I would additionally argue that it should be there anyways; querying between two dates isn't business logic.
The reason you want it in your data layer is that by putting it there you can get the logic as close to the actual DB query as possible (ideally in the query itself); thus allowing the DB engine to do the filter (which they are quite good at) rather than returning a bunch of data you don't actually need (potentially across a network!) to the program and having it do the filter.
Upvotes: 4