list - LiteDB - 通过 List.contains 查找数据对象
问题描述
简化版。我有两节课:
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
现在我知道一个 mEmulator 数据对象在其 List(of mSystem) 中有“Sony Playstation”。但是,test
返回 null。这个怎么找不到?我已经尝试了一些排列,但无法让它发挥作用。有任何想法吗?
解决方案
该Include
方法用于解析对其他集合的引用,并且您没有使用BsonRef
with AssociatedSystems
(至少在您提供的这个示例中没有)。在您的示例中,mSystem
in的实例AssociatedSystems
没有存储在单独的集合中,而是作为 emulators 集合中的嵌入文档数组。
尝试删除Include
呼叫,它应该可以正常工作。
推荐阅读
- docker - docker 客户端如何过滤令牌列表
- asp.net-mvc - 如何在不更改 URL .NET Core 的情况下进行重定向
- java - 如何在 Java 中更改 Jaeger API 的主机和端口
- c++ - 在 Qt 中解析 .xlsx 文件将数据添加到 SQLite DB
- macos - 如何将此脚本更改为仅运行特定月份或年份,而不是查看我的整个照片库?
- jquery - .hide() div 不起作用
- jquery - 如何使用 jquery 在选择框中显示数据值?
- javascript - Facebook 的带有 id 的嵌套对象的 Flow 类型
- ios - 如何在 iOS Swift 中替换特定范围内的字符串?
- sql-server-2012 - SQl Server 和 SQL Azure 有什么区别