if User is a mapped entity then you need not the ResultTransformer.
simply use:
var users = s.CreateQuery("from User u").List<User>();
however, assuming you had a DTO like the following:
class UserInfo
{
string Name {get; set; }
string Email {get; set; }
}
then you can do:
var userInfos = s.CreateQuery("select u.Name, u.Email from User u")
.SetResultTransformer(Transformers.AliasToBean(typeof(UserInfo))
.List<UserInfo>();
2008/9/16 crabo <[EMAIL PROTECTED]>
>
> Have you ever tried? I have never successed.
>
> s.CreateQuery("select u from User u")
> .SetResultTransformer(Transformers.AliasToBean(typeof(User))
> .List();
>
> I'm not using the generic dao.
> Test.UserTest.TestHqlTransformer :
> Spring.Data.NHibernate.HibernateSystemException : Could not execute
> query[SQL: SQL not available]
> ----> NHibernate.Exceptions.GenericADOException : Could not execute
> query[SQL: SQL not available]
> ----> System.NullReferenceException : 未将对象引用设置到对象的实例。
>
>
>
> On 9月12日, 下午3时36分, "Ken Egozi" <[EMAIL PROTECTED]> wrote:
> > s.CreateQuery(hql)
> > .SetResultTransforemer(Transformers.AliasToBean(typeof(DTO))
> > .List<DTO>();
> >
> >
> >
> >
> >
> > On Fri, Sep 12, 2008 at 4:35 AM, crabo <[EMAIL PROTECTED]> wrote:
> >
> > > I really like the following query expression, but I have no success
> > > with my NUnit test.
> >
> > > check out : http://blog.hibernate.org/2133.lace
> >
> > > Hibernate 3.2: Transformers for HQL and SQL
> >
> > > HQL Transformers
> > > Now you can get the value injected via property methods or fields
> > > instead, removing the need for explicit constructors.
> >
> > > List resultWithAliasedBean = s.createQuery(
> > > "select e.student.name as studentName," +
> > > " e.course.description as courseDescription" +
> > > "from Enrolment as e")
> > > .setResultTransformer( Transformers.aliasToBean(StudentDTO.class))
> > > .list();
> >
> > > StudentDTO dto = (StudentDTO) resultWithAliasedBean.get(0);
> >
> > --
> > Ken Egozi.
> http://www.kenegozi.com/bloghttp://www.musicglue.comhttp://www.castleproject.orghttp://www.gotfriends.co.il-隐藏被引用文字
> -
> >
> > - 显示引用的文字 -
>
> >
>
--
Ken Egozi.
http://www.kenegozi.com/blog
http://www.musicglue.com
http://www.castleproject.org
http://www.gotfriends.co.il
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---