Include collection in Entity Framework Core

前端 未结 1 355
灰色年华
灰色年华 2020-12-14 07:25

For example, I have those entities:

public class Book
{
    [Key]
    public string BookId { get; set; }
    public List Pages { get; set; }
         


        
1条回答
  •  醉梦人生
    2020-12-14 07:52

    Try accessing PageTitle directly in ThenInclude:

    using (var dbContext = new BookContext())
    {
        var bookPages = dbContext
        .Book
        .Include(x => x.Pages)
        .ThenInclude(y => y.PageTitle)
        .SingleOrDefault(x => x.BookId == "some example id")
        .Select(x => x.Pages)
        .Select(x => x.PageTitle)
        .ToList();
    }
    

    0 讨论(0)
提交回复
热议问题