I am using DTOs (Data Transfer Objects) to transfer information between the different layers of my application.
What is the best practice when it comes to performance and the way I fill these objects? Should I fill only the minimum required information with different methods from my Data Access Layer?
Let’s say I have the following classes :
public class Order
{
public int OrderNo;
public Customer Customer;
public double Total;
}
public class Customer
{
public int CustId;
public string CustName;
public Country Country;
}
public class Country
{
public int CountryId;
public string CountryName;
}
What happens if I need to generate a list of orders containing the OrderNo, CustName and CountryName and in another situation, different information maybe from different tables (or DTOs)? Would it be best to use a flatten DTO with only the required fields or make a query using LINQ?
I hope I make this clear enough.
Thanks for you help!
Edit: What I want to know is if I should fill all the nested objects and not only a part of the attributes of an object.