Dejan.S
Dejan.S

Reputation: 19118

How to Create a search function with nhibernate, linq?

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

Upvotes: 2

Views: 480

Answers (1)

Nikolay R
Nikolay R

Reputation: 957

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=...)

Upvotes: 2

Related Questions