These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Sql query with custom types
PostPosted: Fri Sep 26, 2008 6:00 am 
Newbie

Joined: Fri Nov 10, 2006 4:42 am
Posts: 6
Hello, I'm trying to execute a sql query like this :

SELECT
Field1 AS {Component1.Field1},
Field2 AS {Component1.Field2},
Field3 AS {Field3}
FROM Table1

And in the code :

....
query.AddScalar("Component1", NHibernateUtils.Class);
query.AddScalar("Field3", NHibernateUtils.String);
query.SetResultTransformer(Transformers.AliasToBean(typeof(MYDTO)));
....

But the query doesn't operate the replace of "{...}".

Is it possbile to do a thing like this?

Thanks in advance.
Andrea


Top
 Profile  
 
 Post subject: Re: Sql query with custom types
PostPosted: Fri Sep 26, 2008 8:39 am 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
Yes, it is possible.
However, I'm not sure how you do it ?

You should make sure that your aliasses are exactly the same name as the properties of your 'DTO' object.
For instance:
Code:
class MyDTO
{
    public int Id {get;set;}
    public string Name {get;set}

    public MyDTO()
    {
       // public default constructor required
    }
}


Code:
ISQLQuery q = session.CreateSQLQuery ( "select EMP_Id AS Id, EMP_Name AS Name FROM tblEmployees" );
q.SetResultTransformer(Transformes.AliasToBean (typeof(MyDTO));

q.List<MyDTO>();


Top
 Profile  
 
 Post subject: query returns case insensitively with capital properties
PostPosted: Tue Oct 21, 2008 4:49 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
I see that my Oracle query is returning these Id and Name as ID and NAME respectively which are not found as properties in the class as they are case sensitive. Any suggestions?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.