Quick question:
When setting up a HasManyConvention, how can I specify that I want the
one-to-many relationships to fetch by join rather than select?
As it stands, the join is left off and it generates a select query for each
relationship. For larger objects without lazyloading, that gets a bit long.
Using build 528 (src/FluentNHibernate/Mapping/IOneToManyPart.cs), it seems
to that the only way to specify the join type is to explicitly add the
attribute.
Convention:
internal class HasManyConvention : IHasManyConvention
{
public bool Accept(IOneToManyPart target)
{
return target.KeyColumnNames.List().Count == 0;
}
public void Apply(IOneToManyPart target)
{
target.KeyColumnNames.Add(target.EntityType.Name + "Id");
*target.SetAttribute("fetch", "join"); *
target.Cascade.AllDeleteOrphan();
target.Inverse();
target.Not.LazyLoad();
}
}
Generated HBM:
<bag name="Observations" cascade="all-delete-orphan" inverse="true"
lazy="false" *fetch="join"*>
<key column="WalkthroughId" />
<one-to-many class="COT.Domain.Observation, COT.Domain,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>
So, that all works... but *should* it? ;)
Perhaps I'm simply using the wrong convention or is there a better way to
manage the joins/conventions for these relationships with auto mapping?
Open to any ideas/suggestions. :)
Thanks!
-dl
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---