How can i perform an LIKE query within Linq?
I have the following query i would like to execute.
var results = from c in db.costumers
where c.FullName LIKE "%"+FirstName+"%,"+LastName
select c;
How can i perform an LIKE query within Linq?
I have the following query i would like to execute.
var results = from c in db.costumers
where c.FullName LIKE "%"+FirstName+"%,"+LastName
select c;
Try using string.Contains () combined with EndsWith.
var results = from c in db.Customers
where c.FullName.Contains (FirstName) && c.FullName.EndsWith (LastName)
select c;
You could use SqlMethods.Like(matchExpression,pattern)
var results = from c in db.costumers
where SqlMethods.Like(c.FullName, "%"+FirstName+"%,"+LastName)
select c;
The use of this method outside of LINQ to SQL will always throw a NotSupportedException exception.
You can use contains:
string[] example = { "sample1", "sample2" };
var result = (from c in example where c.Contains("2") select c);
// returns only sample2
Try like this
var results = db.costumers.Where(X=>X.FullName.Contains(FirstName))
.Where(X=>X.FullName.EndsWith(LastName))
.Select(X=>X);