mercredi 7 décembre 2016

Design pattern for mapping database in Data Access Layer [C#]

I work on my Data Access Layer where I use data mapper pattern. My actual structure of code is for example:

public class Person {
    public int Age
    public string FirstName
    public string LastName
    public List<Address> Addresses
    ...
}

public class PersonMapper {
    public Person GetPersonById(int id)
    public List<Person> GetAll()
    public bool UpdatePerson(Person person)
    ...
}

I have so many classes which are corresponding for database table with same name.

My questions are:

  1. Is my approach right? When I mapped all tables, I will use it in the domain layer.

  2. In Mapper classes I use methods which are working only with tables which are same name as these classes. (Person class -> Persons db table, Order class -> Orders db table, etc.) But what is the best way to map advanced selects from database, which will be contains joins to more tables. For example I want select Person with all his Orders. Should I create domain model for Person which will be contains property List<Orders>and use PersonMapper and next OrderMapper?

Aucun commentaire:

Enregistrer un commentaire