I'm trying to pass a function to a function that accepts an Expression but it only works in the function is a generics one.
This one is what I want but it does not work:
open System
open System.Linq.Expressions
open MongoDB.Driver
type MyObject = { Name:string}
type MyClass () =
// I want to use this
let createFilter (field:Expression<Func<MyObject, string>>, value:string):FilterDefinition<MyObject> =
FilterDefinitionBuilder<MyObject>().Eq(field, value)
member this.CreateFilter<'T> (field:Expression<Func<'T, string>>, value:string):FilterDefinition<'T> =
FilterDefinitionBuilder<'T>().Eq(field, value)
member this.DoSomething(name:string) =
// 1. this does NOT work
let filter = createFilter( (fun x -> x.Name) , name)
// 2. this one works fine
let filter = this.CreateFilter( (fun x -> x.Name) , name)
Why the example 1. does not work?