efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Where clause using List.Contains with one elements results in = instead of IN

Open marqdouj opened this issue 4 years ago • 1 comments

I create my query like this: var search = new List<string> { "SUN" }; return query.Where(e => search.Contains(e.Company)); The SQL output is this: WHERE [c].[Company] = N'sun'

If I add a second value to the list the = becomes IN: var search = new List<string> { "SUN", "TEST" }; return query.Where(e => search.Contains(e.Company)); The SQL output is this: WHERE [c].[Company] IN (N'sun', N'TEST')

I would expect a 'Contains' to always using IN in the above scenarios.

Include provider and version information

EF Core version: 6.0.3 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: NET 6.0 Operating system: Windows 11 Enterprise IDE: Visual Studio 2022 17.1.2

marqdouj avatar Mar 28 '22 19:03 marqdouj

I just realized that with only one element in the list that's correct.

marqdouj avatar Mar 28 '22 19:03 marqdouj