I'm using EF Core 2.2 and have following schema:
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Passport Passport { get; set; }
}
public class Passport
{
public int Id { get; set; }
public string Number { get; set; }
public DateTime IssueDate { get; set; }
public string Authority { get; set; }
public int PersonId { get; set; }
}
When i'm doing following request:
var persons = _context.Persons
.Include(p => p.Passport)
.Select(p => new
{
PersonId = p.Id,
FirstName = p.FirstName,
LastName = p.LastName,
PassportNumber = p.Passport.Number
}).ToList();
EF Core translates it into SQL which contains all the fields of Passport entity. While it's ok for small schema but it can be gap for complicated related entities. Is that possible to make EF Core to send request to db selecting only fields mentioned in LINQ Select statement?
Thank you in advance