I've always tackled this problem using a "4th" layer, and I use that term loosely. We have our Presentation Layer > Client Service Layer > Business Layer > DataAccess Layer.
So in my case, most of the time I don't have access to the Business Layer (in regards of making changes -- as it may affect a lot of other uses for those functions) So I put in a Client Service Layer.
The Client Service Layer is the middle man for communicating between the Presentation Layer and the Business Layer. The Presentation Layer sends all requests that may need to communicate with the Business Layer to the Client Service Layer.
What this allows me to do is to create a generic DTO (Data Transfer Object) that has no requirements on DataSets or DataAccess objects. So in your case, My Presentation Layer would call a class in the Client Service that has a method
Code:
public IList<PersonDTO> GetPersonByRegion(int regionId)
{
List<PersonDTO> personDTO = new List<PersonDTO>();
DataSet1.PersonDataTable dsPerson = adapter.GetDataByRegionId(regionId);
// code to convert DataSet1.PersonDataTable to List<PersonDTO>
// something similar to the following:
for (int i = 0; i < dsPerson.Tables[0].Rows.Count; i++)
{
personDTO.Add(new PersonDTO() { property = dsPerson.Tables[0].Rows[i]["property"] });
}
return personDTO;
}
Now my presentation layer doesn't need to know about a DataSet, it simply needs to know about PersonDTO and IList, which can be pushed as a DataSource to a DataGrid, etc.
Now, one last thing. I ONLY do this if I can't change the Business Layer. If you have the ability to change the business layer to NOT reeturn a DataSet and it can instead return a IList<object>, do that change instead.
Bookmarks