1
如何使用實體框架linq
這樣獲得與NHibernate QueryOver
相同的結果。Nhibernate查詢多個提取和多個條件
var result = items
.include("subEntity1")
.include("subEntity2")
.include("subEntity3")
.where(...).skip(x).take(y);
如何使用實體框架linq
這樣獲得與NHibernate QueryOver
相同的結果。Nhibernate查詢多個提取和多個條件
var result = items
.include("subEntity1")
.include("subEntity2")
.include("subEntity3")
.where(...).skip(x).take(y);
與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>();
來源:
我試試這一個,但我在結果中獲取重複的實體 – user656822
是的,這就是Fetch集合的影響。它總是導致carthesian產品。實際上,恰當的方法是執行** NOT ** Fetch。將您的映射更改爲使用批量大小,該大小將以多於1個查詢結束,但仍然非常有效。請檢查http://stackoverflow.com/a/20970816/1679310或http://stackoverflow.com/a/19287008/1679310 –