-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
support ThenInclude #247
Comments
Actually "ThenInclude" is supported if you add the child to the expression using the Includes or IncludeStrings. My issue though is with the use of magic strings especially when including the children of a collection navigation property. I'll submit a PR to use typed entities as opposed to magic strings. |
Can you provide an example? |
Suppose Brand has a Manufacturer and Manufacturer has an Address, you could include them by chaining them
Or you could use the IncludeStrings property on the BaseSpecification
But like I said I'm doing some refactoring and I'll submit a PR soon. |
Thanks
…________________________________
From: akema-trebla ***@***.***>
Sent: Friday, December 10, 2021 5:20:42 PM
To: fullstackhero/dotnet-webapi-boilerplate ***@***.***>
Cc: dsoltesz ***@***.***>; Author ***@***.***>
Subject: Re: [fullstackhero/dotnet-webapi-boilerplate] support ThenInclude (Issue #247)
var spec = new BaseSpecification<Product>(); spec.Includes.Add(a => a.Brand); var product = await _repository.GetByIdAsync<Product, ProductDetailsDto>(id, spec);
Suppose Brand has a Manufacturer and Manufacturer has an Address, you could include them by chaining them
spec.Includes.Add(a => a.Brand.Manufacturer.Address);
Or you could use the IncludeStrings property on the BaseSpecification
spec.IncludeStrings.Add("Brand.Manufacturer.Address");
But like I said I'm doing some refactoring and I'll submit a PR soon.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#247 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALFFSNCQ46Q62ISBFLNGM3UQJ4LVANCNFSM5JXOIV6A>.
|
that works for single entity but what if brand had a collection of Manufacturers... you need to be able to say Brand.Manufacturers.ThenInclude(man => man.Address) in EF 6 you can do this spec.Includes.Add(o => o.EpisodeConsumerAdvices.Select(e => e.ConsumerAdvice)); but in EF core you need to use ThenInclude |
Yes, I dunno which version of the API you're using but before I submitted #250, you could achieve this using magic strings. Something like Personally, I'm not a fan of magic strings. So I wanted the repository code to use typed entities as much as possible and especially with Includes. Now because of the use of repository pattern we can't have a dependency of EFCore in the Application project to make use of So from #250 onwards you can include children of collection navigation properties using the Select method like you have above. |
Using the select approach wasn't working for me in ef core..that's how I ended up learning about the thenInclude |
Yes, Select no longer works in EFCore out of the box - You need to use ThenInclude. But because I wanted to use typed entities and couldn't use the dependency on EFCore, I had to adopt the EF 6 approach in this project. Hope you get me |
Is your feature request related to a problem? Please describe.
BaseSpecification only supports Include
Describe the solution you'd like
Should support Include.ThenInclude
The text was updated successfully, but these errors were encountered: