开发者

search with list of comma seperated values using linq to sql

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, N开发者_开发技巧ew 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.


var cities = commaSeparatedList.Split(',').Select(p => p.Trim());
var q = _db.People.Where(c => cities.Contains(c.City));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜