Skip to content

Warning when query materializes an entity outside the top projection #12667

Closed as not planned

Description

@divega

One example of when this may happen is if an opaque method that takes an entity as an argument is invoked in the Where clause, e.g.:

var query = context.People
    .Include(p => p.Addresses)
    .Where(p => p.Name.StartsWith(name) && IsCustomer(p));

Given the current behavior, the p passed to IsCustomer won't be tracked, and the Addresses navigation property won't be populated.

If IsCustomer(p) returns false, then that person entity won't end in the query results. For a tracked query that means that the instance will be discarded and not tracked. Moreover, for specific providers (e.g. Cosmos DB), even if IsCustomer(p) returns true, p could be a different object instance from the one that will be included in query results.

Hence the proposal is to make this situation trigger a warning.

Activity

  1. added this to the 3.0.0 milestone on Jul 17, 2018
  2. changed the title [-]Consider warning when query materializes an entity outside the top projection[/-] [+]Warning when query materializes an entity outside the top projection[/+] on Jul 20, 2018
  3. divega commented on Jul 20, 2018

    @divega
    ContributorAuthor

    Note that the scenario above can become very inefficient because for the second query that we create to include the Addresses collection the evaluation of the client predicate will need to fetch from People again. @smitpatel is going to create an issue that optimizes cases like this (and some others) by filtering the second query in terms of the collection of key values obtained from the first query.

  4. smitpatel commented on Jul 24, 2018

    @smitpatel
    Contributor
  5. smitpatel commented on Jan 25, 2019

    @smitpatel
    Contributor

    We decided not to do client eval outside of the top projection. Which means that above query would just throw rather than translating to server (full server translation is not possible). So we don't need to warn anymore.

  6. removed this from the 3.0.0 milestone on Jan 25, 2019
  7. removed their assignment
    on Jan 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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