I have an extension method that lets you generically include data in EF:
public static IQueryable IncludeMultiple(this IQueryable
You can do something like this:
public Patient GetById(int id, Func, IIncludableQueryable> includes = null)
{
IQueryable queryable = context.Patients;
if (includes != null)
{
queryable = includes(queryable);
}
return queryable.FirstOrDefault(x => x.PatientId == id);
}
var patient = GetById(1, includes: source => source.Include(x => x.Relationship1).ThenInclude(x => x.Relationship2));