I know that in manual way I can choose what columns are fetched from database (simplified examples):
db.Products.Where(...).Select(p => new {p.Id, p.Name...})
But, when i have DTO object:
public class ProductDTO {
public int Id { get; set; }
public string Name { get; set; }
public ProductDTO(Product p) {
Id = p.Id;
Name = p.Name;
}
}
and query:
db.Products.Where(...).Select(p => new ProductDTO(p))
from database are fetched ALL FIELDS, not only Id and Name. It's waste of resources.
Why linq can't see what properties are in DTO and fetch only them?
I guess that's what the DTO is for, so that I don't have to write a manual query every time.