Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string based ThenInclude #9730

Closed
jahead opened this issue Sep 8, 2017 · 2 comments
Closed

string based ThenInclude #9730

jahead opened this issue Sep 8, 2017 · 2 comments
Labels
closed-no-further-action The issue is closed and no further action is planned.

Comments

@jahead
Copy link

jahead commented Sep 8, 2017

Context

Hey so I'm currently doing a research project on Implementing HL7 Fhir http://hl7.org/fhir

And even trying to just implement Observations http://hl7.org/fhir/observation.html
Gives you a number of tables if you choose to model the tables correctly. (Not as just one huge Resource Table)

EF Core has actually been quite capable in taking the models and generating a sound Database, and inserting the data correctly, however, trying to retrieve the data has been problematic.
This is due to the requirement to explicitly declare the includes. HL7 FHIR has a strict policy on what must be included and when. And with attempting to include everything is leaving me having to generate a large amount of boilerplate that wasn't necessary in old EF.

I've naively solved this by writing an extension method

public static IQueryable<T> IncludeAll<T>(this IQueryable<T> queryable, DbContext context) where T : class
{
    foreach (var property in context.Model.FindEntityType(typeof(T)).GetNavigations())
        queryable = queryable.Include(property.Name);
    return queryable;
}

When I tried do the same with ThenInclude, there is no method for ThenInclude that takes a string.
The goal was to try and write a recursive function controlled by a depth constraint, so I could implement an IncludeAll Extension

proposal

Add a string overload of ThenInclude that allows us to write our own function that easily uses reflection to generate the Includes/ThenIncludes.

Discussions

I know that this isn't the best solution performance wise, but as it stands the EF Core api doesn't give me a easy way to say Include all these things AND their childs and in fhir that depth can be rather unbounded. So if anyone has workaround, I'm all ears.

What would be an awesome solution would be able to say,

Include this and all of it's childs to some depth

Observation.Include(x => x.Code, true) 

Anyway I digress.

@ajcvickers
Copy link
Member

@jahead The string overload of include supports "dotting through" properties. So instead of:

Observation.Include(x => x.Code).ThenInclude(y => y.Comments);

you can do:

Observation.Include("Code.Comments");

Presumably this "wasn't necessary in old EF" because of lazy loading, which is being tracked as #3797. Also, it seems what you are describing could be a good use of aggregates (#1985) or at least rule-based eager loading (#2953).

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Sep 8, 2017
@jahead
Copy link
Author

jahead commented Sep 11, 2017

Oh okay, cool I'll give that a try and I'll track those issues, thanks.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

2 participants