Zaid-Ajaj / LiteDB.FSharp

Advanced F# Support for LiteDB, an embedded NoSql database for .NET with type-safe query expression through F# quotations
MIT License
181 stars 20 forks source link

Value Id in a function on the Extensions, I don't get any results, nor do I get any error #29

Closed srlopez closed 5 years ago

srlopez commented 5 years ago

When I use the value Id in a function on the extensions, I don't get any results, nor do I get any error. On the other hand with other values everything seems to work correctly. computers.delete(fun c -> c.Id < 4) or computers.findMany (fun c -> c.Id>3) |> Seq.iter (printfn "%A") do not execute anything, do not send error messages. But if I use any other property it works. computers.findMany (fun c -> c.CPU = Intel) |> Seq.iter (printfn "%A") or computers.delete(fun c -> c.Manufacturer.Contains "m") does the work.

Event worse width id in a expression: computers.delete(fun c -> c.Id < myPc.Id-4)

Unhandled Exception: System.Exception: Failed to construct a query from the expression: 
Call (None, op_LessThan,
      [PropertyGet (Some (c), Id, []),
       Call (None, op_Subtraction,
             [PropertyGet (Some (ValueWithName (Computer #103: Dell/1:[...GB],
                                                myPc)), Id, []), Value (4)])])

   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1647.Invoke(String message)
   at LiteDB.FSharp.Extensions.LiteCollection`1.delete[T,t](LiteCollection`1 collection, FSharpExpr`1 expr)
   at Program.main(String[] argv) in /app/Program.fs:line 83
humhei commented 5 years ago

computers.delete(fun c -> c.Id < 4)

Is this a bug? @Zaid-Ajaj

I test it locally

computers.Delete(fun i -> i.Id < 4) take effect. While computers.delete(fun c -> c.Id < 4) doesn't do anything

humhei commented 5 years ago

The same to computers.findMany (fun c -> c.Id>0) (yield nothing) computers.Find (fun c -> c.Id>0) (yield actual results)

Zaid-Ajaj commented 5 years ago

Indeed this doesn't work in with identity fields because I don't expect to query a range of elements using their ID, it doesn't make sense unless you want an exact element by it's ID which is why: