I am using ef-core 2.1, I have a generic abstract base class used for several similar entity types. Controllers inherit this class and invokes the protected methods with generic constraints, something like:
protected async Task<MyResult> GetBase<TEntity, TOut>(int? id)
where TEntity : class, IFoo, IBar
where TOut : class
{
// Construct query.
var query = id == null
? this.Context.Set<TEntity>()
: this.Context.Set<TEntity>()
.Where(p => p.Id == id);
// ...
}
Not all entities share the same navigation properties, so simply extending the interface constraints such that multiple calls to .Include()
would be valid is not possible. Does a means exist to generate a query that automatically includes all related data without explicitly declaring them?