gpt4 book ai didi

访问时的 NHibernate LazyLoad 单个属性

转载 作者:行者123 更新时间:2023-12-04 05:52:35 26 4
gpt4 key购买 nike

我有一个实体映射,其中有三个标记为延迟加载的属性。我的期望是,当我访问单个属性(即缩略图)时,只会加载该属性的数据。但是,如果访问这些属性中的任何一个,NHibernate 似乎将加载所有标记为 LazyLoaded 的属性(即,访问 Thumbnail 也会加载 HighRes 和 LowRes 数据)。

有没有办法改变这种行为?

public sealed class LeakImageMap : ClassMap<LeakImageEntity>
{
public LeakImageMap()
{
LazyLoad();
Table("LeakImage");
Id(x => x.Id).GeneratedBy.GuidComb().UnsavedValue(Guid.Empty);

Map(x => x.FileName).Not.Nullable();
Map(x => x.FileSize).Not.Nullable();
Map(x => x.LeakId).Nullable();

Map(x => x.Thumbnail).Not.Nullable().LazyLoad();
Map(x => x.HighRes).Not.Nullable().LazyLoad();
Map(x => x.LowRes).Not.Nullable().LazyLoad();
}
}

附加信息

访问 image.Thumbnail 会生成以下 SQL:
SELECT
leakimagee_.Thumbnail as Thumbnail14_,
leakimagee_.HighRes as HighRes14_,
leakimagee_.LowRes as LowRes14_
FROM
Hvcs.LeakImage leakimagee_
WHERE
leakimagee_.Id=@p0;
@p0 = 7588d167-22b5-4f2e-b640-9ecb00ed9138 [Type: Guid (0)]

但是,只想拥有以下内容:
SELECT
leakimagee_.Thumbnail as Thumbnail14_
FROM
Hvcs.LeakImage leakimagee_
WHERE
leakimagee_.Id=@p0;
@p0 = 7588d167-22b5-4f2e-b640-9ecb00ed9138 [Type: Guid (0)]

最佳答案

What about multiple lazy properties? NHibernate support them, but you need to keep one thing in mind. NHibernate will load all the entity’s lazy properties, not just the one that was immediately accessed.



来自 Lazy Properties

关于访问时的 NHibernate LazyLoad 单个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5736488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com