Reputation: 54021
I have an Entity
which holds a collection of OtherEntity
in a many-to-many style relationship. The mapping for this property looks like:
HasManyToMany(x => x.OtherEntity)
.AsBag()
.Table("EntityToOtherEntityMapping")
.ParentKeyColumn("EntityId")
.ChildKeyColumn("OtherEntityId")
.Not.LazyLoad()
.Cascade.None();
I notice that when retrieving a collection of Entity
's there's a seperate SQL query for each collection of OtherEntity
.
How can I have Fluent-NHibernate execute this retrieval in one query rather than n?
Upvotes: 1
Views: 681
Reputation: 54021
The answer turned out to be in setting the FetchModel to Eager and selecting a ResultTransformer:
.SetFetchMode("Tags", FetchMode.Eager)
.SetResultTransformer(Transformers.DistinctRootEntity)
Upvotes: 0