English 中文(简体)
NHibernate Address N+1 without usingbatching or Standards AP for an Order->Customer relationship?
原标题:Can NHibernate solve N+1 without using batching or Criteria API for an Order->Customer relationship?

我一直在阅读和探讨以黑白的方式找到答案。

Let s talk about the familiar Customer and Order 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?
最佳回答
问题回答

我只想看一下你正在做的实际询问。 我把我的所有地图都留给了拉齐·洛德,否则就会落空。

I use the Criteria API to query, and I use CreateAlias to join other tables as needed. NHProf is highly recommended to find and eliminate situations like this.

Hi
There are two ways you can address your problem

a) Using Criteria query It will look something like this

Session.CreateQuery(typeof(Order))
.Add(<Restrictions if any>)
.SetFetchMode("Customer",FetchMode.Eager)
.List<Order>();

b) 使用总部

Session.CreateQuery("select o from Order inner join fetch o.Customer where <conditionifany>").List<Order>();

希望。

您使用了什么样的预报?

如果是“波尔图”,你可以使用<代码>join fetch,急切检索一个协会。

LINQ和QueryOver使用.Fetch(





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签