Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq LIKE functionality

so.. I'm using LinqToEntities, and I want to query part of a field. Normally I'd use the LIKE keyword with SQL, and then go from there..

I see that Linq does not have it.. Whats a good way to get the same kind of functionality?

like image 247
KevinDeus Avatar asked Feb 27 '23 22:02

KevinDeus


1 Answers

You can use String.StartsWith() or String.Contains().

For example:

var query = from b in db.Books
            where b.Title.Contains("time")
            select b;

This works because LINQ turns the query into an expression tree, and for LINQ to SQL/Entities, many "standard" C# methods are supported for the conversion to SQL.

like image 109
Neil Barnwell Avatar answered Mar 08 '23 04:03

Neil Barnwell