How can I check whether an eagerly loaded attribute's filed is null in EF core 6?
CodePudding user response:
Quoting MS EF Docs:
Eager loading means that the related data is loaded from the database as part of the initial query.
Then, load it and just check if it is null:
using (var context = new BloggingContext())
{
var blogs = context.Blogs
.Include(blog => blog.Owner)
.ToList();
foreach(var blog in blogs)
{
var no_owner = blog.Owner == null; //< -- here
// ... more code
}
}