2014-02-24 40 views

回答

2

QueryOver語法看起來是這樣的:

var query = session.QueryOver<MyEntity>() 
    // force the collection inclusion 
    .Fetch(x => x.Collection1).Eager 
    .Fetch(x => x.Collection2).Eager 
    ... 
    // force the relations inclusion 
    .Fetch(x => x.SubEntity1).Eager 
    .Fetch(x => x.SubEntity2).Eager 
    ... 
    // paging 
    .Skip(x) 
    .Take(y); 

var list = query 
    .List<MyEntity>(); 

來源:

+1

我試試這一個,但我在結果中獲取重複的實體 – user656822

+0

是的,這就是Fetch集合的影響。它總是導致carthesian產品。實際上,恰當的方法是執行** NOT ** Fetch。將您的映射更改爲使用批量大小,該大小將以多於1個查詢結束,但仍然非常有效。請檢查http://stackoverflow.com/a/20970816/1679310或http://stackoverflow.com/a/19287008/1679310 –