0

A simplified version. I have two classes:

Public Class mSystem

    Public Property ID as ObjectID
    Public Property Name as string

End Class

Public Class mEmulator

    Public Property ID as ObjectID
    Public Property Name as string
    <BsonRef("mSystems")>
    Public Property AssociatedSystems as New List(Of mSystem)

End Class

Public Class Main

    Public Sub EmaultorsLinkedToSystem      

        dim SelectedSystem as mSystem = db.Collections.mSystems.Find(Function(x) x.Name = "Sony Playstation").FirstOrDefault

        test = db.Collections.mEmulators.Include(Function(x) x.AssociatedSystems).Find(Function(y) y.AssociatedSystems.Contains(SelectedSystem)).ToList

    End sub 

End Class

Now I know one mEmulator data object has "Sony Playstation" in its List(of mSystem). However, test returns null. Why isn't this finding it? I've tried a few permutations, but cant get this to work. Any ideas?

stigzler
  • 793
  • 2
  • 12
  • 29

1 Answers1

0

The Include method is used for resolving references to other collections, and you're not using BsonRef with AssociatedSystems (at least not in this example you provided). In your example, the instances of mSystem in AssociatedSystems are not being stored in a separate collection, but as an array of embedded documents in the emulators collection.

Try removing the Include call, it should work fine.

  • Just come back to this as had same problem. You were right, I omitted the . OP changed. How would I achieve the desired outcome in this instance? – stigzler Apr 28 '20 at 19:48