我有一个Entity,它以多对多的方式保存OtherEntity的集合。此属性的映射如下所示:
HasManyToMany(x => x.OtherEntity)
.AsBag()
.Table("EntityToOtherEntityMapping")
.ParentKeyColumn("EntityId")
.ChildKeyColumn("OtherEntityId")
.Not.LazyLoad()
.Cascade.None();我注意到,当检索一个Entity集合时,每个OtherEntity集合都有一个单独的SQL查询。
如何让Fluent-NHibernate在一个查询而不是n个查询中执行此检索?
发布于 2012-06-12 23:39:14
答案是将FetchModel设置为Eager并选择一个ResultTransformer:
.SetFetchMode("Tags", FetchMode.Eager)
.SetResultTransformer(Transformers.DistinctRootEntity)发布于 2012-05-04 04:39:34
在你的属性上添加fetch join。
.Fetch.Join();https://stackoverflow.com/questions/10435704
复制相似问题