I have a procedure in SQL that I am trying to turn into Linq:
SELECT O.Id, O.Name as Organization FROM Organizations O JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId where OH.Hierarchy like '%/12/%'
The line I am most concerned with is:
where OH.Hierarchy like '%/12/%'
I have a column that stores the hierarchy like /1/3/12/ for example so I just use %/12/% to search for it.
My question is, what is the Linq or .NET equivalent to using the percent sign?
The main difference between LINQ and SQL is that LINQ is a Microsoft . NET framework component, which adds native data querying capabilities to . NET languages, while SQL is a standard language to store and manage data in RDBMS.
LINQ to SQL supports all the key capabilities you would expect as a SQL developer. You can query for information, and insert, update, and delete information from tables.
Sql is faster than Linq. Its simple: if I m executing a sql query directly its a one way process whereas if I m using linq, first its been converted to sql query and then its executed.
LINQ query syntax always ends with a Select or Group clause. The Select clause is used to shape the data. You can select the whole object as it is or only some properties of it. In the above example, we selected the each resulted string elements.
.Where(oh => oh.Hierarchy.Contains("/12/"))
You can also use .StartsWith()
or .EndsWith()
.
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