1

我正在尝试过滤记录并将它们返回以将它们放入列表中。我的变量“companyId”等于 1。运行时出现错误。我能做些什么来解决?谢谢你。

错误指向这一行:

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
4

1 回答 1

1

是的,对我来说解决方案很简单:

Dim blogs = db.Blogs.Where(Function(b) b.CompanyId = companyId)
于 2012-08-02T13:04:35.640 回答