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.  [ 2 posts ] 
Author Message
 Post subject: Select only a few fields from a table/map
PostPosted: Mon Dec 14, 2009 1:43 pm 
Newbie

Joined: Mon Dec 14, 2009 1:36 pm
Posts: 1
Hi,

How can I select only a few columns from a table? Let's say I have the following map:

Table("Items");
Id(x => x.ItemId).GeneratedBy.GuidComb().UnsavedValue(Guid.Empty);
Map(x => x.Heading).Length(200).Not.LazyLoad();
Map(x => x.Introduction).Length(500).Not.LazyLoad();
Map(x => x.TimeCreated).Not.LazyLoad();

How can I use CreateCriteria to select only the heading and introduction of a specific item?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Select only a few fields from a table/map
PostPosted: Wed Dec 16, 2009 2:59 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look at the SetProjection method on the criteria:

criteria.SetProjection(Projections.Property("propName"))

criteria.SetProjection(new ProjectionList()
.Add(Projections.Property("propName1")
.Add(Projections.Property("propName2")

http://nhforge.org/doc/nh/en/index.html#querycriteria-projection

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.