2012-08-02 71 views
1

時出錯我試圖篩選記錄並將它們返回以將它們放入列表中。我的變量「companyId」等於1.當我運行時,出現錯誤。我能做些什麼來解決?謝謝。嘗試使用context.entity.include()

錯誤指向該行:

Dim blogs = db.Blogs.Include(Function(b) b.CompanyId = companyId) 

錯誤:

包含路徑表達式必須引用的類型所定義的導航屬性。對於參考導航屬性使用虛線路徑,對集合導航屬性使用Select運算符。 參數名稱:路徑

整個代碼:

' 
    ' GET: /ViewBlogs/ 

    Function ViewBlogs() As ViewResult 
     'Dim blogs = db.Blogs.Include(Function(b) b.Company) 

     Dim db1 As UserProfileDbContext = New UserProfileDbContext 
     Dim user = Membership.GetUser() 
     Dim key As Guid = user.ProviderUserKey 
     Dim userProfile = db1.UserProfiles.Where(Function(p) p.UserId = key).Single 
     Dim companyId = userProfile.CompanyId 

     If (userProfile.IsCompanyOwner) Then 

      Dim blogs = db.Blogs.Include(Function(b) b.CompanyId = companyId) 

      Return View(blogs.ToList()) 

     Else 

      Return View("Home") 

     End If 


    End Function 
+0

訪問這個答案,它可以幫助你-http:/ /stackoverflow.com/questions/5658219/entity-framework-4-1-select – Dayan 2012-08-02 12:50:17

+0

謝謝你我在提交這個問題之前看過那篇文章。我不確定如何在這方面應用它。請幫忙。 – user1477388 2012-08-02 12:51:11

+0

更新:我從使用Include更改爲使用Where。它似乎有效。我會暫時回覆一個答案。 – user1477388 2012-08-02 12:59:30

回答

1

是的,對我來說,解決方案是如此簡單:

Dim blogs = db.Blogs.Where(Function(b) b.CompanyId = companyId)