Reputation: 34800
How can I specify eager loading on a one to many collection within a Fluent NHibernate mapping?
I tried the following but I'm still getting two queries when retrieving the parent object and accessing it's "Features" property:
HasMany<FeatureInstance>(s => s.Features).AsSet()
.Inverse()
.Cascade.SaveUpdate()
.KeyColumn("SiteId")
.Access.ReadOnlyPropertyThroughCamelCaseField()
.Not.LazyLoad();
Thanks Ben
Upvotes: 3
Views: 6171
Reputation: 22379
Even though you have two queries, it's still called eager loading, because both queries are executed immediately (in lazy loading, the second query would only be executed on demand).
If you're looking for a JOIN
SQL query, you can use .Fetch.Join()
to force a JOIN
. But beware that when you later want to get parent objects from the database using a query, the resulting collection will contain several copies of each parent, depending on the number of children (think about how many rows an SQL JOIN
returns...), so in most cases it's not very useful.
Upvotes: 1