views:

68

answers:

1

Say I have the following query

ICriteria query = session.CreateCriteria(typeof(T));

How can I find out the key field of T so that I can add an expression like so

query.Add(Expression.In(keyField, someListOfObjects.ToArray()));

Any ideas?

+3  A: 

Use NH's meta data

var meta = factory.GetClassMetadata(typeof(T));

query.Add(Expression.In(meta.IdentifierPropertyName, someListOfObjects.ToArray()));
Stefan Steinegger
That's great. Thanks.
Mark Dickinson
Just to clear up, var factory = session.SessionFactory;
Mark Dickinson
@Mark: Yes, SessionFactory point to the ISessionFactory you used to create the session.
Stefan Steinegger