IntroductionIn this snippet, we will focus how to use the SQL LIKE operator in LINQ Query. The LINQ is powerful concepts to query data in .NET Framework level as like database query. But way of build query is different from the SQL query. ImplementationI have already built the DataSource for do LINQ Query for this demonstration. The sample records as like below, How to select records for exactly match?LINQ Query var data = from source in provider
where source.GetString(1) == "Wrox"
select source;Sql Query Select * from Source
Where Name='Wrox'; Output How to select records start with a word or character?LINQ Query var data=from source in provider where
source.GetString(1).StartsWith("Wr")
select sourceSql Query SELECT * from Source
Where columnName LIKE 'Wr%' Output How to select records end with word or character?LINQ Query var data= from source in provider where
source.GetString(1).EndsWith("ss")
select sourceSql Query Select * from source
Where columnName LIKE '%ss' Output How to select records with word or character in column?LINQ Query var data= from source in provider
where source.GetString(1).Contains("s")
select sourceSql Query Select * from source
Where columnName LIKE '%s%' Output Hopes help and thank you for reading. |