views:

61

answers:

1

What is the best way to handle the following database search scenario using asp.net mvc, sql server and linq to sql?

I have a simple search for people, by their first name and last name. Based on the results, I would like to dynamically filter the results base on the people's City and Business. This could be multiple cities or businesses (Denver, New York, etc. and Business A, Business B ect.)

Here is some psudeo code of what I need to do:

_db.People.where(p => p.City.Contains(Denver, New York, multiple parameters) 
&& p.Business.contains(Denver, New York, multiple parameters);

I am passing these values back, separated by commas to be searched. Current I am looping through each value to search the database and using the linq to sql .addrange function to build my updated lists. I'm not sure if this is the best way to do this. Is there a way instead to pass in a full list of comma separated values to compare? I'm open to any options, Full Text Search or Stored Proceduce, I'm just not sure where to start.

+3  A: 
var cities = commaSeparatedList.Split(',').Select(p => p.Trim());
var q = _db.People.Where(c => cities.Contains(c.City));
Craig Stuntz
Thanks a lot, that's exactly what I was looking for.
Victor