1

上下文:在容器化环境中运行 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>]当使用. 输出是:DiskComputerprintfn "%A" myPc

Computer #12: Computers Inc./[...GB; ...GB; ...GB]

我还有什么要说的吗?

4

0 回答 0