tags:

views:

66

answers:

1

In NHibernate, Is it possible to do a look up based on an entity passed?

I would like to pass an object from the ui and do a look up based on its values instead of having multiple methods for each possible variation.

For example if I pass a user with the firstname 'John', I'd like to return all users with that firstname.

Any hints much appreciated.

+2  A: 

You can use Find by example method in Nhibernate. Here :

var user=new User();
user.Firstname="John";
var criteria=session.CreateCriteria(typeof(User)).Add(Example.Create(user));

Example is a special kind of expression that builds criterion based on provided entity.

Beatles1692
Thanks for the pointer.
Chin