-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled Exception: ... invalid name ... at LiteDB.BsonDocument.set_Item in 'mutable' field #27
Comments
@humhei |
In fsharp world workaroundCreate a new record instead of setting property mutable open System
open LiteDB
open LiteDB.FSharp
[<StructuredFormatDisplay("a{SizeGb}GB")>]
[<CLIMutable>]
type Disk =
{ SizeGb : int }
[<StructuredFormatDisplay("Computer #{Id}: {Manufacturer}/{DiskCount}/{Disks}")>]
[<CLIMutable>]
type Computer =
{ Id: int
Manufacturer: string
Disks: Disk list }
[<BsonIgnore>]
member __.DiskCount = __.Disks.Length // property calculated
[<EntryPoint>]
let main argv =
let myPc =
{ Id = 0
Manufacturer = "Computers Inc."
Disks =
[ { SizeGb = 100 }
{ SizeGb = 250 }
{ SizeGb = 500 } ] }
printfn "%A" myPc
let mapper = FSharpBsonMapper()
use db = new LiteDatabase("data.db", mapper)
let computers = db.GetCollection<Computer>("computers")
let myDellPc =
{myPc with Manufacturer = "Dell" }
computers.Insert(myDellPc) |> ignore
... |
Hmm even though it is not recommended, I don't see an issue in supporting |
And |
I am afraid that [<CLIMutable>]
type Computer =
{ Id: int
Manufacturer: string
Disks: Disk list }
// this is not persisted
with member this.Ignored = sprintf "%d => %s" this.Id this.Manufacturer Aren't these members good enough for your use-case?
As for |
Fixed and released in version |
* Introduce auto-quoted query expressions, publish 2.7.0 * Support mutable values -> fixes Zaid-Ajaj#27. Take back control of record marshalling * Add tests for ignored members just to be sure, see Zaid-Ajaj#26 * Add support for literal boolean values in query expressions * Support comparison operators for id fields by @humhei at Zaid-Ajaj#31
The
mutable
attribute avoids insert in LiteDB, or passing through Json's encoder, something happens that the name of the field is modified.The field you are trying to modify
Manufacturer
seems to change its nameManufacturer@'
The full error is:
Thanks
The text was updated successfully, but these errors were encountered: