Hi guys
In the context of the n-tier application, is there a difference between what you would consider your data access classes to be and your repositories?
I tend to think yes but I just wanted to see what other thought. My thinking is that the job of the repository is just to contain and execute the raw query itself, where as the data access class would create the context, execute the repository (passing in the context), handle mapping the data model to the domain model and return the result back up...
What do you guys think? Also do you see any of this changing in a Linq to XML scenario (assuming that you change the context for the relevant XDocument)?
Cheers Anthony
UPDATE:
This is the way that I would have typically implemented things previously:
public class TermBl : ITermBl
{
public IEnumerable<ITerm> GetAll(IListParameter criteria)
{
//Any pre business logic
var dataLayer = this.CreateDataLayer();
var result = dataLayer.GetAll(criteria);
//Any post business logic
return result;
}
... Other methods
}
public class TermDa : ITermDa
{
public IEnumerable<ITerm> GetAll(IListParameter criteria)
{
//Linq query
var dataResult = ....ToList()
var mappedResult = this.FromDataToDomain(dataResult);
//Note the mapping isn't done in this object, the actual
// mapping is handled by a separate component
return mappedResult;
}
... Other methods
}
Do you see any inherent problems here with the pattern in general...
As for the repository where I have been thinking of using the it is instead of having the query directly in the TermDa's GetAll method I would change it to look something more like this:
public class TermDa : ITermDa
{
public IEnumerable<ITerm> GetAll(IListParameter criteria)
{
var repository = this.CreateRepository();
var dataResult = repository.GetAll(..., criteria).ToList();
var mappedResult = this.FromDataToDomain(dataResult);
return mappedResult;
}
... Other methods
}
public class TermRepository : ITermRepository
{
public IQueryable<ITerm> GetAll(IMyContext context, IListParameter criteria)
{
//Linq query
return ...;
}
... Other queries
}
Is this how you guys see it working or not really... With or without the repository I see either of the above totally protecting the business layer from knowing anything about the data access methods/technology used...