Say I create a criteria que开发者_开发问答ry and transform it with the AliasToBean result transormer.
session.CreateCriteria<Staff>("s")
.CreateAlias("supervisor", "super")
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("s.name"), "name")
.Add(Projections.Property("super.name"), "supervisor_name"))
.SetResultTransformer(Transformers.AliasToBean<StaffView>());
Is it possible to add a restriction when you only know the property name of the bean? You can AddOrder using the bean property names but the Restrictions only appear to work with the actual property name. I'm guessing this is because they are applied before the transformation, much like you don't use a column alias in a where clause but you can in the order by.
//throws exception like cannot find property supervisor_name in Staff class
//only "super.name" works
.Add(Restrictions.Like("supervisor_name", "blah"))
//this works though
.AddOrder(Order.Asc("supervisor_name"))
So basically I need a way to get the aliased property name based on the alias. I can think of multiple ways to do this, but I was hoping NHibernate had some existing method? I could for example keep a separate map of the property to alias names or just map to a database view so there is no need to transform to bean.
It should work with name of alias dot property name. {alias}.Name.
Or am I misunderstanding your problem?
精彩评论