Skip to content

Query: Navigation rewrite: EF.Property navigations not rewritten correctly #8068

@anpete

Description

@anpete

Using EF.Property instead of a member access can result in different behavior during nav rewrite.

E.g.

  var customers
        = context.Set<Customer>()
              .Select(c => _Include(c, new [] { (object)EF.Property<ICollection<Order>>(c, "Orders") }))
              .ToList();

will generate:

'from Customer c in DbSet<Order>
  where Property([c], "CustomerID") == Property([c], "CustomerID")
  select object IncludeSqlServerTest._Include(
      customer: [c], 
      collections: new object[]{ (object) DbSet<Order> }
   )'

which will then cause:

System.ArgumentNullException : Value cannot be null.
Parameter name: querySource
	at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.AddQuery(IQuerySource querySource, SelectExpression selectExpression)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitEntityQueryable(Type elementType)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.EntityQueryableExpressionVisitor.VisitConstant(ConstantExpression constantExpression)

When using a member access instead, the correct QM is produced:

'from Customer c in DbSet<Customer>
  select object IncludeSqlServerTest._Include(
      customer: [c], 
      collections: new object[]{ (object) ICollection<Order> MaterializeCollectionNavigation(
              navigation: Navigation: Customer.Orders (<Orders>k__BackingField, ICollection<Order>) Collection ToDependent Order Inverse: Customer 0 -1 1 -1 -1, 
              elements: 
                  from Order o in DbSet<Order>
                  where Property([c], "CustomerID") == Property([o], "CustomerID")
                  select [o]
          )
           }
    )
  '

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions