Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# baldec 10/14/2008 4:39 PM
Hello again dear friends. Having finally managed to get the NHibernate I have now run into another thing that I assume can be done in a smoother way.

I have 4 checkboxes symbolising some fields in the DB. And I have a text field with the search criteria.

I want to search on the fields in the db if the checkbox is checked.

Currently the code is as follows
criteria.Add
                (
                    Expression.Or
                    (
                        Expression.Or
                        (
                            Expression.Like("Name", nameCriteria, MatchMode.Anywhere), 
                            Expression.Like("City", cityCriteria, MatchMode.Anywhere)
                        ), 
                        Expression.Or
                        (
                            Expression.Like("Address", addressCriteria, MatchMode.Anywhere), 
                            Expression.Like("Phone", phoneCriteria, MatchMode.Anywhere)
                        )
                    )
                );

And that works just fine if all checkboxes are filled. But if the checkbox aint filled I want to return a false value for the Expression.Like part.

Though I can't for the love of god figure out the correct way to make the criteria match. Currently I solved the issue with
nameCriteria = ? searchCriteria : "xxyyzz";

Which ofc works as long as the guest doesn't manage to enter the jumbled string. Though I am guessing that there is some basic handling of this that I have missed.

Anyone care to enlighten me? :)
# baldec 10/14/2008 4:58 PM
One thought had been before to sort them by
if(name)
{
  criteria.Add(Expression.Like("Name", searchCriteria, MatchMode.Anywhere));
}

THought this gives strict matching, and I was looking for a match in any of the fields.

So anyone know of some nifty thing to add to the criteria? ? :D
# martijnb 10/15/2008 9:24 AM
You can better post these questions at the NHibernate users mailing list (http://groups.google.com/group/nhusers) or the forum (http://forum.hibernate.org/viewforum.php?f=25).

We use NHibernate but at the designated groups, the possibility of a helpful answer is much bigger. For example I don't know an exact answer, but I'm sure it can be done somehow (see, this is not too helpful ;))
# baldec 10/15/2008 2:44 PM
martijnbYou can better post these questions at the NHibernate users mailing list (http://groups.google.com/group/nhusers) or the forum (http://forum.hibernate.org/viewforum.php?f=25).

We use NHibernate but at the designated groups, the possibility of a helpful answer is much bigger. For example I don't know an exact answer, but I'm sure it can be done somehow (see, this is not too helpful ;))

Baah, more forums to keep track off so will see what happens (6)