You could also use a scalar query which fetches the pricefrom in a
projection.
FB
> So no matter how I slice this one I'll have to loop over the items
> collection? Is there a way to issue a smaller query to only get the value
I
> need instead of loading each of the Item objects? Right now I'll get a
> single query for the Store and related Shelves, then I get (in one
> particular instance) 27 calls to grab the Items for each of the 27
shelves.
> Can you expand on how I could possibly reduce the 28 calls? Even if there
> were separate queries, but issued in the same call?
>
> On Aug 23, 11:17 am, Jason Meckley <[email protected]> wrote:
> > there is not a way to efficiently load this in a single query, you can
> > use batch fetching and/or futures to reduce the number of remote
> > calls.
> >
> > On Aug 23, 11:21 am, rhartzog <[email protected]> wrote:
> >
> >
> >
> > > I have a structure similar to this example. On the store detail
> > > page there is a list of the shelves in that store which display a
> > > Priced From value. I can eagerly load the shelves since I know I
> > > will need them, but to calculate the PricedFrom() it lazy loads the
> > > items on each shelf which is obviously not ideal. Most of what I
> > > have worked with is pretty straight forward CRUD queries, but this
> > > could get ugly and I would like to learn how to do something more
> advanced like this.
> >
> > > public class Store
> > > {
> > > public Guid Id { get; set; }
> >
> > > public IList<Shelf> Shelves { get; set; }
> >
> > > }
> >
> > > public class Shelf
> > > {
> > > public Guid Id { get; set; }
> >
> > > public Store Store { get; set; }
> >
> > > public IList<Item> Items { get; set; }
> >
> > > public decimal PricedFrom()
> > > {
> > > return Items.Min(i => i.Price);
> > > }
> >
> > > }
> >
> > > public class Item
> > > {
> > > public Guid Id { get; set; }
> >
> > > public Shelf { get; set; }
> >
> > > public decimal Price { get; set; }
> >
> > > }
> >
> > > public class StoreRepository
> > > {
> > > public Store GetByName(string Name)
> > > {
> > > var store= _session.CreateCriteria<Store>()
> > > .Add(Restrictions.Eq("Name", Name))
> > > .SetFetchMode("Shelves", FetchMode.Eager)
> > > .SetResultTransformer(new
> > > NHibernate.Transform.DistinctRootEntityResultTransformer())
> > > .FutureValue<Store>();
> >
> > > return store.Value;
> > > }
> >
> > > }
> >
> > > public StoreService
> > > {
> > > public StoreDetailVM GetStoreDetails(string Name)
> > > {
> > > Store store;
> > > StoreDetailVM vm;
> > > using (var tx = _session.BeginTransaction())
> > > {
> > > store = _storeRepository.GetByName(Name);
> >
> > > tx.Commit();
> > > }
> >
> > > return Mapper.Map<Store, StoreDetailVM>(store);
> > > }
> >
> > > }
>
> --
> 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.
--
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.