Take a look at:

http://gustavoringel.blogspot.com/2009/02/creating-dto-in-nhibernate-hql-using.html

On Thu, May 7, 2009 at 3:22 PM, bdaniel7 <[email protected]> wrote:

>
> Hello, I'm trying to load 3 properties, from a table SideFrames.
> (I have a class SideFrame also, mapped to the table.)
> For this I created a class SideFrameDTO, with Id, Price, ArtNo.
> I want to execute the query below and get an instance of SideFrameDTO.
>
> But I get "NHibernate.MappingException: No persister for:
> SideFrameDTO"
> I believe because the DTO class is not mapped.
>
> But, is it possible to do this (only 3 props for a smaller class)?
>
> Thank you,
> Dan
>
> string query = @"select
>        p.Id as {sideFrameDTO.Id},
>        p.PricePerUnit as {sideFrameDTO.Price},
>        p.ArticleNumber as {sideFrameDTO.ArtNo}
> from SideFrames sf join Products p on p.Id = sf.SideFrameId
> where sf.Size = :sizeID and sf.Material = :materialID";
>
> IQuery sqlQuery = session.CreateSQLQuery( query )
>                .AddEntity( "sideFrameDTO", typeof ( SideFrameDTO ) );
>
> sqlQuery.SetParameter( "sizeID", SizeID );
> sqlQuery.SetParameter( "materialID", MaterialID );
>
>
> sqlQuery.SetMaxResults( 1 );
> return sqlQuery.UniqueResult< SideFrameDTO >();
> >
>

--~--~---------~--~----~------------~-------~--~----~
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