Do a Like Statement in LINQ in C#

There has been a few times I needed to do a like statement in LINQ, but didn’t know exactly how to go about it. Just in case there are you out there looking for the same, I thought I would post what I did. For example, say you had this SQL statement :

SELECT * FROM Autos WHERE Manufacturer LIKE '%Fo%'

This would translate to LINQ code in C# like the following

dbContext.Autos.Where(a=> a.Manufacturer.Contains("Fo")).AsEnumerable();

Releated Post

Leave a Reply

%d bloggers like this: