F#LiteDB [<bsonignore>]被忽略了吗?

时间:2019-05-03 14:10:46

标签: f# attributes bson litedb

上下文:在容器化环境中运行F#

$ dotnet --version 2.2.203
$ uname -a
Linux SAFE 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64 GNU/Linux

在Ubuntu 18.04台式机上。

此简单代码忽略了[<BsonIgnore>]属性。 Ignore的值存储在LiteDB中。难道我做错了什么? 我已经通过使用控制台命令$ dotnet LiteDB.Shell.dll micompany.db进行了检查:

...
> open micompany.db
> db.computers.find
[1]: {"_id":11,"Ignore":"ignore","Manufacturer":"Computers Inc.","Disks":[{"SizeGb":100},{"SizeGb":250},{"SizeGb":500}]}

这是代码:

open System
open LiteDB
open LiteDB.FSharp

[<StructuredFormatDisplay("{SizeGb}GB")>]
[<CLIMutable>]
type Disk = 
    { SizeGb : int }

[<StructuredFormatDisplay("Computer #{Id}: {Manufacturer}/{Disks}")>]
[<CLIMutable>]
type Computer =
    { Id: int
      [<BsonIgnore>] Ignore : string
      Manufacturer: string
      Disks: Disk list }

[<EntryPoint>]
let main argv =

    let myPc =
        { Id = 0
          Ignore = "ignore"
          Manufacturer = "Computers Inc."
          Disks =
            [ { SizeGb = 100 }
              { SizeGb = 250 }
              { SizeGb = 500 } ] }

    let mapper = FSharpBsonMapper()
    use db = new LiteDatabase("micompany.db", mapper)
    let computers = db.GetCollection<Computer>("computers")

    // Insert & Print
    computers.Insert(myPc) |> ignore
    printfn "%A" myPc

    0 // return an integer exit code

另一方面,当[<StructuredFormatDisplay>]记录用{打印时,Disk记录的Computer属性未正确写入(控制台中仅出现了几个点) {1}}。输出为:

printfn "%A" myPc

还有什么要说的吗?

0 个答案:

没有答案
相关问题