2

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?

JoseK
  • 31,141
  • 14
  • 104
  • 131
user842684
  • 21
  • 3

1 Answers1

2

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

Firo
  • 30,626
  • 4
  • 55
  • 94