Skip to content

Query: Use of types that are neither entities nor anonymous inside a query triggers client-side evaluation #8107

Closed

Description

@divega

For a query that internally projects into an range variable of a type which is not recognized as either an entity type or an anonymous type, any subsequent query operators is evaluated in memory even if the range variable is not present in the final projection.

In theory we could recognize more common cases in which intermediary types can be eliminated from the query. This can improve how we process queries with nominal types that are not anonymous types (e.g. DTOs), property bags, tuples, etc.

In some of those cases we would need to have knowledge of specific getter and setter patterns to be able to correlate different RHS and LHS expressions representing the same members.

cc @anpete

Activity

  1. changed the title [-]Query: Use of non-entity types and non-anonymous types inside a query triggers client-side evaluation[/-] [+]Query: Use of types that are neither entities nor anonymous inside a query triggers client-side evaluation[/+] on Apr 7, 2017
  2. added this to the Backlog milestone on Apr 12, 2017
  3. smitpatel commented on May 16, 2017

    @smitpatel
    Contributor

    @divega - Can you post an example query here?

  4. divega commented on May 17, 2017

    @divega
    ContributorAuthor

    @smitpatel I haven't tested any specific query with this problem but based on the conversation with @anpete that made me to file the issue, I believe something like this should do:

    var cs = db.Customers
        .Select(c => new CustomerDto {Id = c.Id, Name = c.Name})
        .OrderBy(dto => dto.Name)
        .ToList();

    The query could use a tuple or a dictionary instead of CustomerDto, or initialize it using a constructor, or have fields instead of properties. There is a spectrum of patterns we could recognize, regular class with properties being likely the most common.

  5. smitpatel commented on May 17, 2017

    @smitpatel
    Contributor

    The above posted query should work. #8198 Implemented code for it. (also added test similar to above). Basically at this stage we support, object initialization syntax.
    Initialization through a constructor may be incorrect to translate as we don't know what processing constructor does. (like what is constructor is adding +1000 to id column)
    I am not sure what is pattern in which fields can be used instead of properties.

    Tuple/Dictionary are not recognized perhaps rare patterns. Which caused us to use AnonymousObject for new IncludeCompiler

  6. divega commented on May 17, 2017

    @divega
    ContributorAuthor

    Good to know that we support object initializers beyond anonymous types already. This issue is then about everything else that is possible and it is fine for it to remain in the backlog. You are right that the constructor thing requires some trust and would only "be correct" (i.e. work the same regardless of where it is evaluated) work if the object definition follows certain convention. Incidentally we would have similar requirements to work with constructors and factories for materialization.

  7. self-assigned this
    on Sep 1, 2018
  8. modified the milestones: Backlog, 3.0.0 on Sep 1, 2018
  9. smitpatel commented on Sep 1, 2018

    @smitpatel
    Contributor

    Consider scenario in #12728

  10. smitpatel commented on Jan 25, 2019

    @smitpatel
    Contributor

    We decided in design meeting that
    We will allow following types inside subquery to be transparent to query and not cause creation of object which avoids client eval like above.

    • Anonymous types
    • Nominal types
    • Tuples (optional for 3.0)
    • Dictionary (optional for 3.0)

    We will not assume types to be transparent if it is created without parameterless ctor since we cannot guarantee of the processing inside the ctor.

  11. smitpatel commented on Jun 5, 2019

    @smitpatel
    Contributor

    We have added support for this in 3.0

  12. modified the milestones: 3.0.0, on Jun 5, 2019
  13. modified the milestones: , 3.0.0 on Nov 11, 2019
  14. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions