D
D
Dmitry2017-02-06 23:11:02
ASP.NET
Dmitry, 2017-02-06 23:11:02

What is the pattern for the data access layer?

Hello! For the data access layer, I chose the data table gateway, there is such a model

public class Player
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public string Position { get; set; }
 
    public int? TeamId { get; set; }
    public Team Team { get; set; }
}
 
public class Team
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Coach { get; set; }
 
    public ICollection<Player> Players { get; set; }
    public Team()
    {
        Players = new List<Player>();
    }
}

CRUD methods are implemented in the data table gateway, the question arose of what to do if on one page I need to get information only about Team, and on another page I need to get information about Team with Players, you can always load Team with Player, but what if is the inclusion tree big enough? Can choose another pattern, tell me what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
unsafePtr, 2017-02-07
@unsafePtr

Service Pattern + Inversion of control. We return Dto (Data transfer object) from the service layer, always, since we follow the canons. If you want to return Team with Player, just create a method in the service and implement the logic in the body of the function

List<TeamPlayer> GetTeamPlayers(int teamId)
{
  //logic
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question