Skip to content

Sparse fields stops working when DefaultEntityRepository.Get() overriden #475

Closed
@milosloub

Description

@milosloub

Description

Steps to reproduce:

  1. I have model like this (reduced for simplicity)
public class Client: Identifiable
{
      [Attr]
      public string FirstName { get; set; }

      [HasOne]
      public Advisor Advisor { get; set; }
      public int AdvisorId { get; set; }
}
  1. I have registered custom repository with Get() override:
        public override IQueryable<Client> Get()
            => base.Get()
                .Where(e => e.AdvisorId == 1);
  1. I made request: GET /api/clients?fields[clients]=firstName
  2. Empty array is returned and console shows:

warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'where (new Client() {Id = [x].Id, FirstName = [x].FirstName}.AdvisorId == 1)' could not be translated and will be evaluated locally.

I can see, that there is strange translation with Where condition (There is statament that belongs to Select query)
I think, that using this line cause the problem

return source.Provider.CreateQuery<TSource>(Expression.Call(

Do you have any idea how to fix this? I can make PR, but I have no idea how to combine those
Provider.CreateQuery, standard LINQ query builder, selects and where queries...

Environment

  • JsonApiDotNetCore Version: 3.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions