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();

Jacob Saylor

Software developer in Kentucky

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: