English 中文(简体)
在一页结果内装上多个儿童收藏品
原标题:Eager loading multiple child collections within a paged result

我已远远超出了我的民族解放能力,似乎......。

我试图把一个有3个儿童藏书的实体的“顶10”装上,但“NHibernate s Linq”的实施给我带来了正确的结果......其代价是把所有儿童的表格装上。

public class PartnerDto : BaseDto
{
    private IList<EmailContactDto> _emailContacts;
    private IList<TelephoneNumberDto> _telephoneNumbers;
    private IList<string> _chains;
    public EmailContactDto[] EmailContacts
    {
        get { return _emailContacts.ToArray(); }
        set { _emailContacts = value.ToList(); }
    }
    public TelephoneNumberDto[] TelephoneNumbers
    {
        get { return _telephoneNumbers.ToArray(); }
        set { _telephoneNumbers = value.ToList(); }
    }
    public string[] Chains
    {
        get { return _chains.ToArray(); }
        set { _chains = value.ToList(); }
    }
    //more properties
}

绘图:

<class name="PartnerDto" table="[Partner]" schema-action="none" lazy="false" mutable="false">
<id name="Id">
  <generator class="hilo"/>
</id>
<bag name="Chains" table="PartnerChains" access="field.camelcase-underscore" lazy="false" fetch="subselect">
  <key column="PartnerId"/>
  <element column="Chain" type="System.String"/>
</bag>
<bag name="TelephoneNumbers" access="field.camelcase-underscore" lazy="false" fetch="subselect">
  <key column="PartnerId"/>
  <composite-element class="TelephoneNumberDto">
    <property name="Name" not-null="true"/>
    <property name="ClickToDial" not-null="true"/>
    <property name="SMS" not-null="true"/>
    <property name="Index" column="[Index]" not-null="true"/>
  </composite-element>
</bag>
<bag name="EmailContacts" access="field.camelcase-underscore" lazy="false" fetch="subselect">
  <key column="PartnerId"/>
  <composite-element class="EmailContactDto">
    <property name="Name" not-null="true"/>
    <property name="Email" not-null="true"/>
    <property name="NewsLetter" not-null="true"/>
    <property name="Index" column="[Index]" not-null="true"/>
  </composite-element>
</bag>
<!-- other properties -->

当我去做:

session.Query<PartnerDto>().Take(10);

我得到正确的10份回馈,但我的ql显示,它装上电话簿表、电子邮件Contact表和伙伴Chains表格中的所有各行,而不是将其限制在10个伙伴Im装载上。

我失踪了什么? (Yes,我必须非常急切地装载——在盘问之后,必须按顺序排列。)

EDIT:创始解决办法:

我先问一下,只看一页的问答,然后问一下使用这些Id s的全标的图表。 由于“十大”目前位于该条款的范围之内,因此NHibernate也用于过滤。 是的,这并非完美无缺,我有两点四点四点四点四点四点四点四点四点四点四点三点,但我目前仍然最选择。

最佳回答

使用batch-size关于您的收藏品的编号与您的页数相同,并删除lazy=“false”

这将使用单一查询方式获取每一种收集类型。

它最容易地这样做,也是最有效的办法之一。

当然,本届会议必须保持开放,直到您将物体序列化为止。

问题回答

我认为,这个问题与林克托无关。 由于你急切地重提收集工作,因此国家人类发展报告受到限制,导致出现一个单一质询,同时可以排位(第10级),因为从非行获得的原始成果中,再没有一种与创纪录的关系。





相关问题
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. ...

热门标签