More data than required

The About component we were creating consumes the Person entity, which contains a lot of information that is not necessary for the component, but still it is processed and returned to the View. We can see in the following code, the  AboutComponent  consumes the GetPersonByIdQuery and returns the entire Person entity to the View:

    public IViewComponentResult Invoke(int id)    {      var user = _repository.GetSingle(      new GetPersonByIdQuery(_context)      {        IncludeData = true,        Id = id      });      return View(user);    }

The preceding View component renders only the Name and Biography properties of the user entity. We can see them in the following view component code:

    <h2>About @Model.Name</h2>    <p>      @Model.Biography    </p>

The View component then ...

Get Mastering Entity Framework Core 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.