Feat: implementation of includes#118
Conversation
| /// If the client doesn't request any sort expressions, these expressions will be used for sorting instead. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| protected virtual string[] GetDefaultSortExpressions() |
There was a problem hiding this comment.
The more I think about it... it's may needed and overriden by custom subclasses.
I've seen the same method in MappedDocumentMaterializer.
Is this it needed?
There was a problem hiding this comment.
If you want to sub-class QueryableToManyRelatedResourceDocumentMaterializer and provide default sort expressions for a particular endpoint in the case the client does not provide their own sort expressions, this would be the only way to do it. I was doing precisely this in my own project at one point, which is why I added the method.(although I've since switched to my own custom implementation of IRelatedResourceDocumentMaterializer).
There was a problem hiding this comment.
Ok, I supposed so just after deletation. I'll bring it back.
This one was not clear to me at the first glance... I'll bring it back too.
if (sortExpressions == null || sortExpressions.Length < 1)
sortExpressions = GetDefaultSortExpressions();`|
In private IQueryable<TResource> Filter<TResource>(Expression<Func<TResource, bool>> predicate,
params Expression<Func<TResource, object>>[] includes) where TResource : class
{
IQueryable<TResource> query = DbContext.Set<TResource>();
if (includes != null && includes.Any())
query = includes.Aggregate(query, (current, include) => current.Include(include));
if (predicate != null)
query = query.Where(predicate);
return query.AsQueryable();
}It seems to me there is an implication on includes but I don't unterstand exactly what should happend and where the includes should be filled in. At the moment Thanks for some suggestions. |
|
@spike83 You're right - somehow that capability got lost at some point. Both related resource materializer classes should add something like the following: to allow overriding classes to specify navigation properties to include. |
…rkDocumentMaterializer because they are never used and replaced with EntityFrameworkToManyRelatedResourceDocumentMaterializer and EntityFrameworkToOneRelatedResourceDocumentMaterializer
|
@csantero ok if I got it right the GetIncludes method you suggested is not directly related to the includes in the resulting document. It's for eager loading...? since |
…ResourceDocumentMaterializer
|
I think it's almost done. |
|
@spike83 let me know when you're done and I'll take a closer look for review. |
|
For my needs it works like a charm. So I'm done. Please have a strict look what is missing and can be improved before merge. I also enabled the epic github new feature |
|
@spike83, thanks, this is great! |
Feat: implementation of includes (JSONAPIdotNET#118)
added basic IncludeExpressionExractor and introduced includes on EFDocumentMaterializer
will do more testing