How can i search in LINQ as stated below?? I Want to enter a string like this "a%b%c%d%" in my textbox and want result as we get in SQL.
Select *
from TableName
Where ColumnName Like 'a%b%c%d%'
How can i search in LINQ as stated below?? I Want to enter a string like this "a%b%c%d%" in my textbox and want result as we get in SQL.
Select *
from TableName
Where ColumnName Like 'a%b%c%d%'
LINQ doesn't have like operator, so you could first check if it contains a, b, c and d, then check if a is at start, b is before c, and c before d. Like this:
from item in context.TableName
where item.ColumnName.StartsWith("a") && item.ColumnName.IndexOf("b") != -1
&& item.ColumnName.IndexOf("c") != -1 && item.ColumnName.IndexOf("d") != -1
&& (
item.ColumnName.IndexOf("b") < item.ColumnName.IndexOf("c")
&& item.ColumnName.IndexOf("c") < item.ColumnName.IndexOf("d")
)
select item;
FROM item in context.TableName
WHERE item.ColumnName.StartWith("a%")
OR item.ColumnName.StartWith("b%")
OR item.ColumnName.StartWith("c%")
OR item.ColumnName.StartWith("d%")
SELECT item;