Skip to content

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

@divega

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions