The first problem there is "a Stored Proc that populates a grid".
You've got to change the way you look at this *radically* if you want to
take advantage of NHibernate.

I'll give you some starting steps.
- Create a rich domain model that represents your entities and their
relationships (mapped as references, not Ids)
- Map your domain to the DB. You can use XML, Fluent or ConfORM, whatever
you like best
- Design your view, with the corresponding data bindings. You can take two
approaches here:
  - Pass the domain objects and bind to nested properties. For example,
Name, AuthorAddress.State, etc
  - Build DTOs/Presentation Models from your domain objects exposing just
what the grid needs. For example BookName, AuthorAddressState, etc.
- Build a simple query that retrieves the root objects. You can use HQL,
Criteria, Linq...
- Optimize your query and mappings using joining, batching and caching to
improve performance as needed

   Diego


On Wed, Jun 23, 2010 at 19:05, Mike <[email protected]> wrote:

> I'm trying to figure out how to do complicated queries in NHibernate.
> I'm trying to refactor a Stored Proc that populates a grid to an
> NHibernate query, but I'm having problems because it joins a dozen
> tables.  I'm aware of setting FetchModes in NHibernate; however, it
> just seems like it's going to be difficult to recreate the results of
> this query in OO format instead of tabular format.  Here's an example
> query:
>
> SELECT
>   Book.ID,
>   Book.Name,
>   Author.Name,
>   AuthorAddress.State,
>   Publisher.Name,
>   PublisherAddress.State
> FROM
>   Book
>      INNER JOIN Author ON (Author.ID = Book.AuthorID)
>      INNER JOIN Address AuthorAddress ON (AuthorAddress.ID =
> Author.AddressID)
>      INNER JOIN Publisher ON (Publisher.ID = Book.PublisherID)
>      INNER JOIN Address PublisherAddress ON (PublisherAddress.ID =
> Publisher.AddressID)
>
> Now this is a mocked up example, but you can see the Joins go more
> than one level deep.  After I figure in dynamic sorting and paging,
> the Stored Proc yields the exact structure I want to show in my grid.
> I'm having problems replicating this with NHibernate.  Any advice out
> there?  Should I be taking a different approach?  I thought about
> keeping a stored procedure and loading it to a simple DTO for display
> in my grid, but there's domain logic I would love to include in the
> grid, and I'd hate to replicate it.
>
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

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