给出了团队->运动员关系,并询问了所有运动员。我对fetch="Join"有什么误解?此映射是否应导致通过join加载团队?当迭代运动员时,它仍然懒惰地加载团队。
public class AthleteMap : ClassMapping<Athlete>
{
public AthleteMap()
{
ManyToOne(a => a.Team, o =>
{
o.Fetch(FetchKind.Join);
o.Lazy(LazyRelation.NoLazy);
}
);
}
}它产生了这个HBM:
<class name="Athlete" table="Athletes">
<id name="Id" type="Int32" />
<property name="FirstName" />
<property name="LastName" />
<many-to-one name="Team" fetch="join" lazy="false" />
<property name="Created" />
</class>迭代:
var session = factory.OpenSession();
foreach (var athlete in session.Query<Athlete>())
Console.WriteLine("{0} {1}", athlete.FirstName, athlete.Team.Name); 发布于 2011-11-23 05:36:30
NHibernate Linq查询不使用映射的fetch策略。您必须像这样在linq查询中获取()。
var session = factory.OpenSession();
foreach (var athlete in session.Query<Athlete>().Fetch(x => x.Team))
Console.WriteLine("{0} {1}", athlete.FirstName, athlete.Team.Name); 映射文档中定义的获取策略会影响:
通过Get()或Load()
来源:performance-fetching
https://stackoverflow.com/questions/8232420
复制相似问题