2012-08-02 76 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)