-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Simplify pattern for Include around collections/references #1709
Comments
We actually had it working in this case. We just removed the extra overload because it seemed redundant to me.
It is not nice in this case it is not really needed. |
We discussed this and we will try IncludeCollection/IncludeReference (or is it IncludeMany/IncludeOne for consistency?) because that accounts for the corner cases in which the CLR type does not match the conceptual cardinality of the navigation property. We should consider doing #1481 at once since we are touching these methods and it might get harder to do it later. |
I would like to bring this back to discussion. The more I think about it the more I believe this is going to complicate much more than simplify things. |
I confirmed that this won't be necessary and that all we need to do is bring back the following "reference" overload of public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableQueryable<TEntity, TPreviousProperty> source,
Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath)
where TEntity : class
{ This is in addition to the existing "collection" overload: public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableQueryable<TEntity, ICollection<TPreviousProperty>> source,
Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath)
where TEntity : class
{ I confirmed that the latter handles different collection types correctly because as part of #1491 we already made I also played with the corner case in which an entity type implements
ctx.Customers
.Include(c => c.Orders)
.ThenInclude(o => o.OrderLines)
.ThenInclude(ol => (ICollection<ProductPresentation>)ol.Product)
.ThenInclude(pp => pp.Description); Finally, Intellisense inside |
Sweet, yeah the implementing ICollection is a corner case so needing to a bit of casting etc. is fine I think 😄. This work item was about the more general need to simplify the pattern... so it can now just track the pattern listed above. We should reconsider this when we get to the EntityEntry API for navigation properties... I think we should keep the Collection/Reference API we had in EF6 there... but we should at least have the discussion. |
BTW we should verify that this correctly resolves on non-Roslyn compilers too |
I verified on both. |
…nces Added ThenInclude overload for a reference. Also added tests that were removed when the overload was removed previously.
…nces Added ThenInclude overload for a reference. Also added tests that were removed when the overload was removed previously.
…nces Added ThenInclude overload for a reference. Also added tests that were removed when the overload was removed previously. CR: Diego, Andrew
Fixed with d271361 |
Currently you can only use ThenInclude after landing on a collection nav but you can't use it after landing on a reference in the previous Include call. This is super hard to describe/document... and that's a good sign it will be confusing.
Historically, trying to use overload resolution to detect collection/reference has never worked. So the proposal is to do the same Reference/Collection named pairs of methods we use elsewhere in the stack:
We would still allow the dotted syntax but it wouldn't be the primary API we push folks too.
When discussing this we should also consider using the Reference/Collection names in the relationship API (rather than One/Many).
Once decided on this we need to add API docs. I removed them for the moment because the current pattern is hard to describe and if we are going to change it I don't want to waste time working out how to word it 😄
The text was updated successfully, but these errors were encountered: