What I want to do is to be able to use projections with queryover. I have succeeded doing this using projections on first level only using AliasToBean Transformer but when i project on properties from a detail class nhibenate throws the following exception:
Could not find a setter for property 'FirstContact' in class 'Model.Personnel.Entities.Employee'
at NHibernate.Properties.ChainedPropertyAccessor.GetSetter(Type theClass, String propertyName)
at NHibernate.Transform.AliasToBeanResultTransformer.TransformTuple(Object[] tuple, String[] aliases)
at NHibernate.Loader.Criteria.CriteriaLoader.GetResultList(IList results, IResultTransformer customResultTransformer)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
at NHibernate.Impl.CriteriaImpl.List(IList results)
at NHibernate.Impl.CriteriaImpl.List[T]()
at NHibernate.Criterion.QueryOver`1.List[U]()
at NHibernate.Criterion.QueryOver`1.NHibernate.IQueryOver<TRoot>.List[U]()
at Tests.Entities.EmployeeFacts.QueryEmployees()
This is my current code:
Employee anEmployee = null;
Contact aContact = null;
session.QueryOver(() => anEmployee).Left
.JoinAlias(() => anEmployee.Contact, () => aContact)
.OrderBy(() => aGender.Name).Asc
.ThenBy(() => aContact.FirstContact).Asc
.SelectList(builder => builder.Select(() => aContact.FirstContact)
.WithAlias(() => aContact.FirstContact)
.Select(() => anEmployee.FirstName)
.WithAlias(() => anEmployee.FirstName))
.TransformUsing(Transformers.AliasToBean(typeof(Employee)))
.List<Employee>();