I have a string "Word1 Word2" and I want to transform it to a query such as "Like '%Word1%Word2%'".
At the moment I have:
from t in Test
where t.Field.Contains("Word1 Word2")
How to do this in LINQ2SQL? Do I need to create two separate queries for this, can't I write it in the same statement?
Thx in advance
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.
LINQ is the basic C#. It is utilized to recover information from various kinds of sources, for example, XML, docs, collections, ADO.Net DataSet, Web Service, MS SQL Server, and different database servers.
The Linq Contains Method in C# is used to check whether a sequence or collection (i.e. data source) contains a specified element or not. If the data source contains the specified element, then it returns true else return false.
LINQ StartsWith , EndsWith , and Contains are case sensitive and return false if two same string s are of different cases, e.g., " STRING " and " string ".
from t in Test
where SqlMethods.Like(t.Field, "%Word1%Word2%")
select t
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