Searching and Linq

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?
 
M

Martin Honnen

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').
 
A

Andy

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top