When I use EF Core linq query, and order the list by inner object's property. If the inner object is null, it will not throw exception.
For example:
var Posts = await context.Post .Where(p => p.BlogId == 1)) .Include(p => p.Author) .OrdeyBy(p => p.Author.Name) .ToListAsync();
If one of Author
in Post
is null
, the query still can be executed successfully.
But if I order a list, which is not query by EF Core. For example, I order an existing list Posts
:
Posts.OrderBy(p => p.Author.Name).ToList()
It will throw a null reference exception. Like this metioned: Check object null inside orderby Linq
What make their different? Why EF Core linq order is not impact by null reference?