与this question类似,我正在尝试使用LiteDB文档中的示例,并在运行时出现错误:
Invalid BSON data type 'Null' on field '_id'.
下面是我的代码,其中包括我为解决该问题所做的尝试,即添加注释on the github, here中的_id和Id声明
Public Class Customer
Public _id As LiteDB.BsonValue
Public Id As Integer
Public Name As String
Public Phones As String
Public IsActive As Boolean
End Class
Public Class ThisAddIn
Shared Sub testSub()
Dim db As New LiteDB.LiteDatabase(Directory.GetCurrentDirectory() & "\DEPDB.db")
Dim col As LiteDB.LiteCollection(Of Customer)
col = db.GetCollection(Of Customer)("customer")
Dim tCustomer As New Customer
tCustomer.Id = 1
tCustomer.Name = "John Doe"
tCustomer.Phones = "12354534"
tCustomer.IsActive = True
col.Insert(tCustomer)
end sub
end class
答案 0 :(得分:0)
将类声明略微更改为:
Public Class Customer
Public Property Id As Integer
Public Property Name As String
Public Phones As String
Public IsActive As Boolean
End Class
允许编译和运行代码,并使用以下命令搜索“名称”字段:
col.EnsureIndex(Function(x) x.Name)
Dim tresult = col.FindOne(Function(x) x.Name.Contains("Jo"))
MsgBox(tresult.Name)
尽管如此,我还是偶然遇到了这个解决方案,在声明中添加了文字……任何解释将不胜感激。