2012-04-06 67 views
0

我試圖做的是參考MSDN article明確加載相關實體時應用過濾器

我嘗試這樣做:

dbContext.Entry(entry) _ 
    .Collection(Function(c) c.relObjects) _ 
    .Query() _ 
    .Where(Function(c) c.MyCondition) _ 
    .Load() 

但它不會編譯,說的load()不是IQueryable的

的一員,我看到的是它的目標EF5。 有沒有辦法讓它在EF4中工作?

+0

C#或VB.NET?您使用'vb.net'語法通過'c#'標記了問題。 – abatishchev 2013-02-02 02:02:20

回答

0

Where條件返回一個IQueryable對象。

dbContext.Entry(entry).Collection(Function(c) c.relObjects).Load() 

From msdn: 你應該相關型號對象的集合後使用負載即使延遲加載禁用,仍然可以通過顯式調用的Load方法懶洋洋地加載相關實體相關實體的條目。例如

// Load the department related to a given course using a string  
context.Entry(course).Reference("Department").Load();  
// Load the courses related to a given department 
context.Entry(department).Collection(Function(c) c.Courses).Load(); 
1

我知道這是舊的文章,但要確保你導入System.Data.Entity命名空間:

Imports System.Data.Entity 

.Load方法實際上是在該命名空間的擴展方法。

+0

你明星,那就是我想念的! – Alxwest 2013-03-08 17:11:02