Searching and Linq

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hi,

I'm trying to update some custom code to linq. The issue I'm hitting
is this. The user can enter several keywords (no limit on how many),
and I'm searching a field in the database and I'd like to return
anything that has at least ONE of the keywords matching.

Any way to acomplish this with linq?
 
Andy said:
I'm trying to update some custom code to linq. The issue I'm hitting
is this. The user can enter several keywords (no limit on how many),
and I'm searching a field in the database and I'd like to return
anything that has at least ONE of the keywords matching.

Any way to acomplish this with linq?

Is that LINQ to SQL? It should translate a

List<string> keywords = new List<string>();
keywords.Add("foo");
keywords.Add("bar");

var query = from record in db.SomeTable
where keywords.Contains(record.field)
select record;

into a SQL field IN ('foo', 'bar').
 
Back
Top