How can I do a [MemberNotNull] for an Entity Framework IncludeAll() method I wrote?

David Thielen 1,426 Reputation points

I have the following helper method. This includes all complex properties in my Event DbSet (actually there's 9 properties but I reduced it for clarity):

public static IQueryable<Event> IncludeAll(this IQueryable<Event> source)
    return source
        .Include(e => e.Description)
        .Include(e => e.Tags)
        .Include(e => e.Thumbnail);

I use it as follows:

_event = await dbContext.Events
    .FirstOrDefaultAsync(e => e.Id == pkEvent);

When I do this, I get warnings in that call that it may need Description, Tags, & Thumbnail. And in the first use of each, again warnings that they may be null.

Is there a way to do something like the following:

public static IQueryable<Event> IncludeAll(this IQueryable<Event> source)

That (declaring MemberNotNull) does not work.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
591 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,031 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 44,646 Reputation points