0

我需要从 User.UserId = 不管和 Courses.Status=active 的 Courses 类中获取所有子文档数组

Public Class User
    Public Property UserId As String 'this is unique so i would like to index this, unless you think otherwise
    Public Property CourseData() As List(Of Courses) ' 
    Public Property Groups As List(Of String)   
    Public Property BU As List(Of String)     
End Class

Public Class Courses
    Public Property id As String 'this can be dynamic
    Public Property description As String
    Public Property CompletionDate As String
    Public Property Hours As String
    Public Property Status As String
End Class

使用 vb.net ,我尝试了几种方法,我只希望将返回的具有 Status="Active" 的课程转储到 Ienumberable

我试过(_users 是用户的集合)(_uid 是传递给它的变量)

Return _users.FindAs(Of User)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid))))
Return _users.FindAs(Of User)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid)))).SetFields("Courses", "1")

Return _users.FindAs(Of Courses)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid))))
Return _users.FindAs(Of Courses)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid)))).SetFields("Courses", "1")

似乎都不起作用,他们通常会从班级用户或班级用户和班级课程中返回字段,但课程字段为空白

我什至在尝试 linq .. 这有效 - 但只返回 1 行结果

Dim uc =  From _u In _users.AsQueryable(Of User)()
    Where _u.userid = _userid _
    Select _
CourseID = _u.Courses.Where(Function(c) c.State = "Submitted").Select(Function(c) c.CourseId)(0), _
CourseDescription = _u.Courses.Where(Function(c) c.State = "Submitted").Select(Function(c) c.CourseDescription)(0)

看起来很简单,就是搞不定

4

1 回答 1

0

知道了,我想我想多了

一旦我声明了一个类的实例,我就可以遍历子文档

Dim _u as new User
For Each c In _user.Courses.Where(Function(cs) cs.Status= "Active").Select(Function(cs) cs) 
console.writeline(c.id & c.description & "so on...")
Next
于 2014-04-15T11:35:03.840 回答