I am using Entity Framework Core 3.1.4. My Model is like-
public class Review
{
[Key, Required]
public Guid Id { get; set; }
public int Rating { get; set; }
public DateTime WatchDate { get; set; }
public virtual Guid UserId { get; set; }
public virtual User User { get; set; }
}
My controller is like this-
public async Task<IActionResult> Index()
{
var data = await _context.Reviews
.Include(r=>r.User)
.Select(r => new Review {
Id = r.Id,
WatchDate = r.WatchDate,
User = r.User,
Rating = r.Rating
})
.OrderByDescending(r => r.Rating)
.ToListAsync();
return View(data);
}
It is doing fine, but it is querying all data of the User
table like this (red marked areas)-
But I need only email
, so I like to select only email (yellow marked one) from there. I am doing Select
in the upper level, but can't do the same thing in the inside element. As far as I know, there was a way in Entity Framework like this. But the code is not working as version changed.
Can anyone please help, how can I accomplish it?
How can I include only user email in the list, not all data? So how can I select nested entry?