Skip to content

Unnesssary left joins when entity uses member body projectable #222

Description

@stephan-playbk

Env:

EntityFrameworkCore.Projectables 6.0.6, EF Core 10.0.3, Npgsql.EntityFrameworkCore.PostgreSQL 10.0.0, .NET 10

Given the following:

public class Root
{
    public Guid Id { get; set; }
    public int Units { get; set; }
    public List<Leaf> Leaves { get; set; } = [];

    [Projectable(UseMemberBody = nameof(ComputedExpression))]
    [NotMapped]
    public int Computed { get; set; }
    private static Expression<Func<Root, int>> ComputedExpression => x => x.Units * 2;
}

The following queries result in:

db.Roots.AsNoTracking().ToQueryString();  // LEFT JOIN "Leaves"  <-- unexpected
db.Roots.ToQueryString();                 // no join             <-- expected

If the above entity had 13 navigation properties (as was the case in our code), there would be 13 left joins on them.

The fix is to either Remove AsNoTracking() or make Computed get-only.

Activity

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