Skip to content

Include: The associated data in the query result is empty, select error is reported #17856

@luy710

Description

@luy710

using (var context = new BloggingContext())
{
var blogs = context.Blogs
.Include(blog => blog.Posts)
.ThenInclude(post => post.Author)
.ThenInclude(author => author.Photo)
.Select(Blogs => new BlogsItem{
Name = Blogs.Posts.Author.Name
});
}
假设 Blogs Posts Author为1对1关系
Name = Blogs.Posts.Author.Name 如果Blogs.Posts 为空 或者Blogs.Posts.Author为空会报错,这种如何处理呢?

Translation:

Assume that Blogs Posts Author is a one-to-one relationship
Name = Blogs.Posts.Author.Name If Blogs.Posts is empty or Blogs.Posts.Author is empty, it will report an error. How do I handle this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions