流利Nhibernate加载不会延缓加载? (孙子实体) [英] Fluent Nhibernate loading not falling back on lazy loading? (grandchild entities)

查看:153
本文介绍了流利Nhibernate加载不会延缓加载? (孙子实体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当查询nhibernate时,我看到一些奇怪的行为。当我写这样的查询时,

<

($ = $ x code> Repository.QueryOver< Entity>(
.Fetch(x => x.Child1).Eager
.Fetch(x => x.child2) .eager

它会急切地抓住child1和child2的实体,但有child1和child2的孙子懒洋洋地装着。我有点困惑如何实现这一点。

在我的nhibernate映射,似乎没有影响的懒惰或孙子孙子,我至少需要为了避免N + 1查询问题,一些实体被急切地加载。

我也想知道如何在我的原始实体下急切地加载孙子实体。



任何帮助或想法都会被赞赏!

解决方案

我会建议使用<批量抓取。正如这里所讨论的,流利的语法是:

<1> 设置

  HasMany< MyEntity>(x => x.Entities)
。批量大小(100);



<2> class 级别设置


  public MyEntityMap()
{
Id(x => x ....
...
BatchSize(100);

这个设置应该适用于每个集合和每个类。流利的 - 我们可以使用 惯例 - 看更多例如这里


'IClassConvention ' - 用来改变你的ClassMaps值,你不能用这个约定来改变属性,集合等,只能改变 Lazy BatchSize


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

'IClassConvention' - Use to alter your ClassMaps values. You can't change properties, collections, etc with this convention, only alter the settings such as Lazy and BatchSize.

这篇关于流利Nhibernate加载不会延缓加载? (孙子实体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆