问题描述
当查询nhibernate时,我看到一些奇怪的行为。当我写这样的查询时,<
($ = $ x code> Repository.QueryOver< Entity>(
.Fetch(x => x.Child1).Eager
.Fetch(x => x.child2) .eager
它会急切地抓住child1和child2的实体,但有child1和child2的孙子懒洋洋地装着。我有点困惑如何实现这一点。
在我的nhibernate映射,似乎没有影响的懒惰或孙子孙子,我至少需要为了避免N + 1查询问题,一些实体被急切地加载。
我也想知道如何在我的原始实体下急切地加载孙子实体。
任何帮助或想法都会被赞赏!
我会建议使用。正如所讨论的,流利的语法是:
设置
HasMany< MyEntity>(x => x.Entities)
。批量大小(100);
class 级别设置
public MyEntityMap()
{
Id(x => x ....
...
BatchSize(100);
这个设置应该适用于每个集合和每个类。流利的 - 我们可以使用 惯例
- 看更多例如
When querying nhibernate, I'm seeing some odd behavior
When I write a query like this
Repository.QueryOver<Entity>()
.Fetch(x => x.Child1).Eager
.Fetch(x => x.child2).Eager
It will eagerly grab child1 and child2 entities, but there are grandchildren for child1 and child2 that aren't lazily loaded. I'm a bit confused on how to achieve this.
In my nhibernate mappings, it seems to have no affect on the laziness or eagerness of grandchildren and I require at least some entities be eagerly loaded to avoid the N+1 query problem.
I'm also wondering how I could eagerly load grandchildren entities under my original entity.
Any help or ideas are appreciated!
I would suggest to use the batch-fetching. As discussed here, the fluent syntax is:
1) the collection setting
HasMany<MyEntity>(x => x.Entities)
.BatchSize(100);
2) the class level setting
public MyEntityMap()
{
Id(x => x....
...
BatchSize(100);
This setting should be applied on every collection and every class. To do that with fluent - we can use Conventions
- see more e.g. here
这篇关于流利Nhibernate加载不会延缓加载? (孙子实体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!