look into Projections. projections can be done with any of the query
methods (HQL, Criteria, Linq, Sql). for example
//hql
var bookDTOs = session
.createquery("select new BookDTO(b.id,
b.Title, a.Name) from Book b join b.Author a where ...)
.SetParameter(...)
.List<BookDTO>();
//criteria
var bookDTOs = session.createcriteria<Book>()
.CreateAlias("Author", "a")
.Add(Restrictions.Whatever(...))
.SetProjection(Projections.List()
.Add(Projections.Id())
.Add(Projections.Property("Title"))
.Add(Projections.Id("a.Author")))
.SetResultTransformer(Transformers.EntityToBean(typeof(BookDTO)))
.List<BookDTO>();
this works for read-only data. if you want to edit the entities, then
you should load the full entity, end and let NH manage the change
tracking.
On Aug 9, 11:09 am, MattO <[email protected]> wrote:
> NHUsers,
>
> I'm investigating nHibernate and I'd like to know how to minimize the
> amount of network bandwidth the SQL querys nHibernate will generate.
> By default nHibernate will return all the propertys of a business
> objects when I go and retrieve the data. But in many cases I know
> exactly what propertys i'd use and only want to return say 3 of the 80
> propertys of a business object.
>
> Here is an example:
>
> I have an "Items" table with 80 fields.
>
> I retrieve all 80 fields as follows:
>
> manager.GetByID("1"); //Return my item object with an ID of one.
>
> This results in all 80 fields being populated from the database.
>
> Say I just need 3 of the 80 fields (The ID, NAME, and QTY fields).
> How do I do this in nHibernate so that I minimize the amount of data
> that gets sent back from the database server and my client PC?
>
> I'm wondering if you do it somehow this way:
>
> sess.CreateSQLQuery("SELECT ID, NAME, QTY FROM
> ITEMS").AddEntity(typeof(Items));
>
> I don't expect to do any updating to these objects (I know all the
> other fields would be blank and we would maybe overwrite them if we
> ever saved them to the database???)
>
> Thanks!
--
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.