Fluent NHibernate Linq Complex Component Eager Loading
We are using Fluent NHibernate LINQ in our project with legacy database. Our scenario is that we have a table with Customer information with address. We have created Customer and Address as separate entities in C#. Address again references zip code object.
While mapping, we have mapped Address as Component of Customer. Now I want to eager load Zip Code (which is referenced by Address) while fetching Customer so as to avoid N+1 selects.
When I try to write Fetch(customer => customer.Address.ZipCode)
it says its too complex. I cannot开发者_开发技巧 do Fetch(customer => customer.Address).ThenFetch(address => address.ZipCode)
since Address is stored in same table as Customer.
Is there any way I can solve this problem?
unfortunatly it seems the Linq-provider cant handle this situation. So either you use criteria or QueryOver API
session.CreateCriteria<Customer>()
.SetFetchMode("Address.ZipCode", FetchMode.Eager)
.List();
session.QueryOver<Customer>()
.Fetch(u => u.Address.ZipCode).Eager
.List();
Or disable LazyLoading of ZipCode in Mappings
精彩评论