follow this thread:
How can I do a [MemberNotNull] for an Entity Framework IncludeAll() method I wrote?
David Thielen
3,121
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
.IncludeAll()
.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:
[MemberNotNull(nameof(Picture))]
public static IQueryable<Event> IncludeAll(this IQueryable<Event> source)
That (declaring MemberNotNull) does not work.