s

C# linq where like query edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 21 September 2020 | 3480

I have a C# list of countries with properties Id and Name. I would like to filter the countries by Name with a like, like how you would using a SQL query like below

select * from SetupCountry where Name like '%Ind%'

Solution

solution is use the Contains with the Where LINQ

filter = "Ind";
List Countries = new Country().Get();
var retval = Countries.Where(x => x.Name.Contains(filter));