12
我正在使用Entity Framework 4.1代碼的第一種方法。實體框架4.1默認預先加載
我想作爲我的默認配置進行熱切加載,並避免在每個獲取查詢中使用Include擴展方法。
我一樣recomended在MSDN,在構造函數中的DbContext改變簡單懶屬性:
public class EMarketContext : DbContext
{
public EMarketContext()
{
// Change the default lazy loading to eager loading
this.Configuration.LazyLoadingEnabled = false;
}
}
不幸的是,這種做法是行不通的。我必須使用Include方法在每個查詢中執行預先加載。任何想法爲什麼? 在此先感謝。
根據ADO.Net開發人員的說法,您錯了。檢查了這一點:http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading-related-entities.aspx? CommentPosted = true#commentmessage – Sean 2011-05-18 09:12:24
不,我沒有錯。我知道這篇文章,並沒有任何部分會描述「永久性'包括'」 – 2011-05-18 09:22:04
請看(中間):「關閉所有實體的延遲加載」。 – Sean 2011-05-18 09:28:17