views:

145

answers:

1

I am going to build a search function today, c# asp.net. i need a push go get it rolling. i use nhibernate linq. it would be nice to do this with linq query. it need to be kinda dynamic, i am going to have several search criterias like gender, email, name, age and some more.

this search query is only going to my customer object.

how could i do this? and how is this done the right way?

the way i think now is that i get a iqueryable and perform queryies to that. i think like this that e.g for the gender i got two checkboxes, so i perform a if male is check i do a where.gender == "Male" and if none is checked i do nuthing. but is this the way to do this for every query? because some is user input to like name, email, age.

please advice me on this

+1  A: 

You could analyze your search filter like this:

var query==...
if (filter.Name.Length>0)
   query=query.Where(name=...)
if (filter.Email.Length>0)
   query=query.Where(email=...)
Nikolay R
great. while i am at it, if i want to perform a search for the entiere page like in the news, pictures ect.. how could i do that?
Dejan.S
You mean in one query? I think (unless it's a bottleneck) you can use multiple queries.
Nikolay R