Skip to content

Generate IN expression for tuples #898

@roji

Description

@roji

We could translate to the following PostgreSQL-specific syntax:

SELECT *
FROM Table
WHERE (Id, Type) IN ((1, 1), (2, 1))

LINQ for this could be:

var blogs = ctx.Blogs
   .Where(p => (new[] { new { Id = 1, Type = 1, Title = "New" } })
      .Contains(new { p.Id, p.Type, p.Title }))
   .ToList();

Or for entity equality:

var blogs = ctx.Blogs.Where(b => new[]
{
    new Blog { Id = 1, Type = 1 },
    new Blog { Id = 2, Type = 1 }
}.Contains(b)).ToList();

We could even translate Any/All to this.

Originally requested by @dmitryshunkov in dotnet/efcore#14661 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions