Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq2SQL to produce Like operator

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

like image 227
Dante Avatar asked Apr 13 '10 11:04

Dante


People also ask

How to check LIKE operator in LINQ?

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.

What is LINQ in C# with example?

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.

How use contains in LINQ?

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.

Is LINQ case sensitive?

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 ".


1 Answers

from t in Test
where SqlMethods.Like(t.Field, "%Word1%Word2%")
select t
like image 118
Peter Willis Avatar answered Sep 17 '22 11:09

Peter Willis