LINQ To SQL Wildcards

Posted by mcass20 on Stack Overflow See other posts from Stack Overflow or by mcass20
Published on 2010-06-08T18:27:59Z Indexed on 2010/06/08 18:32 UTC
Read the original article Hit count: 373

How can I build in wildcards to my LINQ To SQL lambda expression?

This is what I have currently:

var query = from log in context.Logs select log;
foreach (string filter in CustomReport.ExtColsToFilter)
{
    string tempFilter = filter;
    query = query.Where(Log => Log.FormattedMessage.Contains(tempFilter));
}

This works fine up until I try and pass wildcards in the filter string. I'm experimenting with SqlMethods.Like() but to no avail.

The filters above look like this: "<key>NID</key><value>mcass</value>".

I'd like to be able to pass filters like this: "<key>NID</key><value>%m%</value>"

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql