Using SQL “IN” Clause in LINQ Query

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)

Console.WriteLine(item);

Console.ReadLine();

Using SQL "IN" Clause in LINQ Query

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...