Simplify translation of Contains over subquery using IN
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Given the following LINQ query:
```c#
_ = ctx.Blogs
.Where(b =>
ctx.Blogs
.OrderBy(b2 => b2.Id)
.Take(10)
.Select(b2 => b2.Id)
.Contains(b.Id))
.ToList();
```
We currently translate to the following SQL:
```sql
SELECT [b].[Id], [b].[Name]
FROM [Blogs] AS [b]
WHERE EXISTS (
SELECT 1
FROM (
SELECT TOP(10) [b0].[Id]
FROM [Blogs] AS [b0]
ORDER BY [b0].[Id]
) AS [t]
WHERE [t].[Id] = [b].[Id])
```
We could instead translate to the following:
```sql
SELECT [b].[Id], [b].[Name]
FROM [Blogs] AS [b]
WHERE [b].[Id] IN (
SELECT TOP(10) [b0].[Id]
FROM [Blogs] AS [b0]
ORDER BY [b0].[Id]);
```
Contributor guide
Assessment
This issue has not been assessed yet.