Using SQL “IN” Clause in LINQ Query

Your 2020 Plan. Learn 20 minutes a day for 20 days. Online courses from €9.99.

When using the SQL Query, we could use the IN keyword to find the item something like this

SELECT * FROM MOVIES WHERE Movie_Name IN ('Thalaivaa', 'Jilla', 'Arrambam')

How to use achieve the similar results when using LINQ?

Using SQL “IN” Clause in LINQ Query

You could use the contains extension method to achieve the similar result as shown in the below code snippet.

string[] MovieNames = new string[] { "Thuppaki", "Thalaivaa", "Jilla", "Arrambam" };

string[] CurrentName = new string[] { "Thalaivaa", "Jilla", "Arrambam" };

var selectedName = (from u in MovieNames

where CurrentName.Contains(u)

select u);

foreach (var item in selectedName)



Using SQL "IN" Clause in LINQ Query

Leave a Reply

Your email address will not be published. Required fields are marked *