Skip to content

QueryRewrite: implement complex cases of entity equality and enable relevant tests #15260

Description

@maumar

example query:

from p in ps
where p.OrderDetails.Contains(
	ods.OrderByDescending(o => o.OrderID).ThenBy(o => o.ProductID)
		.FirstOrDefault(orderDetail => orderDetail.Quantity == 1))
select p

this can be translated to:

from p in ps
where p.OrderDetails.Select(x => x.Id).Contains(
	ods.OrderByDescending(o => o.OrderID).ThenBy(o => o.ProductID)
		.FirstOrDefault(orderDetail => orderDetail.Quantity == 1).Id)
select p

but in case of composite keys we need to be more creative, e.g.

from p in ps
where p.orderDetails.Join(
		ods.OrderByDescending(o => o.OrderID).ThenBy(o => o.ProductID)
			.Where(orderDetail => orderDetail.Quantity == 1).Take(1),
			p => { p.Key1, p.Key2 }, od => { od.Key1, od.Key2 }).Any()

Activity

  1. self-assigned this
    on Apr 5, 2019
  2. added this to the 3.0.0 milestone on Apr 5, 2019
  3. assigned and unassigned on Jun 5, 2019
  4. modified the milestones: 3.0.0, Backlog on Jun 21, 2019
  5. assigned and unassigned on Mar 6, 2020
  6. smitpatel commented on Mar 16, 2020

    @smitpatel
    Contributor

    Related #20164

  7. removed their assignment
    on Aug 27, 2020
  8. 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

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions