To see if it had an effect, I changed this.  I made ThingOrder a component 
which *includes* the reference to the Thing, and used a regular HasMany 
(Bag).  The ThingsOrder now has to search the lists instead of using a 
dictionary lookup, but the lists tend to be small (~100 items max).  Doing 
it this way, the *Things*, are *not* loaded when iterating over the 
contents.

On Tuesday, December 15, 2015 at 8:29:29 AM UTC-5, Trinition wrote:
>
> I have a class that stores some meta data about sort order and defaults 
> for Things.  When I iterate over the dictionary, the keys are being loaded 
> one-by-one.  In my iteration, the only thing I'm doing (see 
> thingOrderAction) is accessing it's mapped identity, so it shouldn't 
> require loading the entity.  Yet at runtime, each entity key *is* being 
> loaded!  NHProf has pointed at the *foreach* line itself (not the 
> action).  Is this an inherent behavior of NHibernate dictionaries with 
> entity keys?
>
>
> public class ThingsOrder
> {
>     private readonly IDictionary<Thing, ThingOrder> _thingOrders = new 
> Dictionary<Thing, ThingOrder>();
>     ...
>     public virtual void ExportThingOrders(Action<Thing, ThingOrder> 
> thingOrderAction)
>     {
>         foreach (var relativeOrderPair in _thingOrders) // <-- Here's the 
> SELECTs!!!!!
>         {
>             thingOrderAction(relativeOrderPair.Key, 
> relativeOrderPair.Value);
>         }
>     }
>
> }
>
>  
>
> public class ThingOrder
>
> {
>
> public int RelativeOrder { get { return _relativeOrder; } }
> private readonly int _relativeOrder;
>
> public bool Selected { get { return _selected; } }
> private readonly bool _selected;
>
> }
>
>      
>
> This is mapped as an IDictionary, keyed by an entity (Thing) and whose 
> value is a component (ThingOrder).  Via Fluent NHibernate, that's:
>
>             HasMany(Reveal.Member<ThingsOrder, IDictionary<Thing, 
> ThingOrder>>("_thingOrders"))
>                 .Table("usr_ThingsOrderRelativeOrders")
>                 .KeyColumn("ID")
>                 .Not.KeyNullable()
>                 .AsEntityMap("ThingID")
>                 .Not.Inverse()
>                 .Component(m =>
>                 {
>                     m.Map(x => x.RelativeOrder);
>                     m.Map(x => x.Selected);
>                 })
>                 .Cascade.AllDeleteOrphan()
>                 .LazyLoad();
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to