Tech Talk A software developer on all things tech, and then some


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();
Tagged as: , , , Leave a comment
Comments (0) Trackbacks (0)

No comments yet.

Leave a Reply

No trackbacks yet.

%d bloggers like this: