我一直在阅读和探讨以黑白的方式找到答案。
Let s talk about the familiar
Customer
andOrder
problem. Let s say I load 100 orders, and each order is linked to one and only one customer.
Using Fluent NHibernate, I will use References()
to link my Order
to Customer
and I will define my Not.LazyLoad()
and Fetch.Join()
as well.
Now I am thinking hypothetically, NHibernate can simply join these two tables and would be pretty easy to hydrate entities. However, in my tests I always see rather N+1 queries (in fact perhaps only the unique IDs). I can share my code and tables but it might bore you, so
- Is it possible to overcome N+1 for Order->Customer (one->one or rather Many->One)? Or I have to use batching or Criteria API?
- If possible can you please point me to an Fluent NHibernate example?