Sorry for my poor description above. I have use Hibernate and
NHibernate for more than 1 years .
so I do know the SetResultTransformer API.  and also the HQL or
mapping classed means.

You got my point:
var userInfos = s.CreateQuery("select u.Name, u.Email from User u")
 .SetResultTransformer(Transformers.AliasToBean(typeof(UserInfo))
 .List<UserInfo>();

I really want a " partial object query" . the different is ,I want my
DTO is just the mapping entity.
so I test:
var userInfos = s.CreateQuery("select u.Name, u.Email from User u")
 .SetResultTransformer(Transformers.AliasToBean(typeof(User))
 .List()

But also encounter the NULL exception above.

Thanks very much!

On 9月17日, 上午3时27分, "Fabio Maulo" <[EMAIL PROTECTED]> wrote:
> Ors.CreateQuery("select u.Name, count(*) from User u group by u.Name order
> by u.Name")
> .SetResultTrasformer(new YourTransformer<YourType>())
> .List<YourType>();
>
> Or
> s.CreateQuery("select u.Name, count(*) from User u group by u.Name order by
> u.Name")
> .SetResultTrasformer(new PositionalToBeanResultTransformer(typeof(Something),
> new string[]{"name","count"}))
> .List<YourType>();
>
> 2008/9/16 Ken Egozi <[EMAIL PROTECTED]>
>
>
>
>
>
> > 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.castle...藏被引用文字
> >> -
>
> >> > - 显示引用的文字 -
>
> > --
> > Ken Egozi.
> >http://www.kenegozi.com/blog
> >http://www.musicglue.com
> >http://www.castleproject.org
> >http://www.gotfriends.co.il
>
> --
> Fabio Maulo- 隐藏被引用文字 -
>
> - 显示引用的文字 -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to