我正在尝试过滤记录并将它们返回到列表中。我的变量“companyId”等于1.当我运行时,我收到错误。我该怎么办?谢谢。
错误指向此行:
Dim blogs = db.Blogs.Include(Function(b) b.CompanyId = companyId)
错误:
Include路径表达式必须引用在类型上定义的导航属性。使用虚线路径作为参考导航属性,使用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 :(得分:1)
是的,我的解决方案就像这样简单:
Dim blogs = db.Blogs.Where(Function(b) b.CompanyId = companyId)