2010-06-09 77 views
2

使用调用setFetchMode我有这样的方法:问题NHibernate的

public IEnumerable<Album> GetAllAlbumsWithTracks() 
    { 
     var albums = Session.CreateCriteria(typeof(Album)) 
      .SetFetchMode("Tracks", FetchMode.Eager) 
      .SetResultTransformer(new DistinctRootEntityResultTransformer()).Future<Album>(); 

     return albums; 
    } 

,但如果我设置.SetMaxResult(10)我回来10首歌曲没有相册。我该如何解决?

+0

类似http://stackoverflow.com/questions/3221482/nhibernate-eager-loading-collections-paging? – David 2011-01-18 21:48:05

回答

1

尝试设置提取模式的加入

+1

如果我不添加SetMaxResult,我会在单个查询中找回所有内容。 如果我设置FetchMode.Join&SetMaxResult然后我得到曲目。 如果我设置FetchMode.Select&SetMaxResult然后我得到专辑,但我得到 选择N + 1没有一个单一的查询。 如何在单个查询中获得10个相册? – CurlyFro 2010-06-09 19:36:56