Specify eager loading within Fluent NHibernate Mapping
How can I specify eag开发者_JS百科er 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
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.
I think you have to define a fetch strategy as well. see here.
精彩评论