SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    3 Layer principe and data return/capture question

    I have 3 layered architecture

    I am using strongly typed data set in data access layer.

    In my business logic layer i have

    using DataAccess;
    using DataAccess.DataSet1TableAdapters;


    public DataSet1.PersonDataTable GetPersonByRegion(int regionId)
    {
    return adapter.GetDataByRegionId(regionId);
    }

    my understanding is i would need dataset of type DataSet1.PersonDataTable to capture value returned from this function in UI layer...for which i would have to refer to DataAccess layer in UI which i feel is not right as per 3 tier principle

    now how do i get the value from this function with out referring or initializing link to DataAccess or making object of DataSet1.PersonDataTable type in presentation layer....

    If i have to do
    using DataAccess; or
    using Data;

    in presentation layer, is it violation of 3 tier model principle which says UI should not talk directly to dataacess layer...



    so how do i tackle this...
    I am bit new to dot net. In php i use to return array and no need to initialize any type of data object in presentation layer...

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,649
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    It is 2013, there is really no reason to use a dataset.

  4. #4
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks @cpradio
    I think I got the point.
    Yup I can change business tier so just to keep simple I will change business tier function as listed above.

    @wwb_99
    Thanks. Yup I totally agree but just modifying small part of legacy system for a client....now convincing him to give up dataset may be another task (lol)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •