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;
To find the duplicate values only:var duplicates = list. GroupBy(x => x. Key). Where(g => g.
In LINQ to SQL, we don't have a LIKE operator, but by using contains(), startswith(), and endswith() methods, we can implement LIKE operator functionality in LINQ to SQL.
The popular answer is that LINQ is INtegrated with C# (or VB), thereby eliminating the impedance mismatch between programming languages and databases, as well as providing a single querying interface for a multitude of data sources.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With