I try to find all posts in RavenDB containing the word (index is)
Here is a query that works, finds everything that starts with "Liv"
let post = query { for post in session.Query<MyType>() do where (post.Text.StartsWith("Liv")) select post }
Trying to use the string.Contains () method as a Where clause condition will throw a NotSupportedException. Here
Therefore, I am trying to use a search method, where:
Expression<Func<T, object>> fieldSelector,
C # equivalent from docs:
List<User> users = session .Query<User>("Users/ByNameAndHobbies") .Search(x => x.Name, "Adam") .Search(x => x.Hobbies, "sport") .ToList();
My first attempt was to go with
let x = session.Query<MyType>(index).Search((fun xe -> xe.Text ), "Liv")
But get an error because it expects an object. Tried dragging String into Object (what a strange idea), but getting:
Unable to figure out how to translate x => x.Invoke (xe)
At the moment I have no ideas. I have to check the box for searching and returning an object. Any ideas?
Thanks.
EDIT 1: My expression. Gets a runtime InvalidCastException because it cannot distinguish a string from obj.
let expr = <@ Func<MyType, _>(fun xe -> xe.Text ) @> |> LeafExpressionConverter.QuotationToExpression |> unbox<System.Linq.Expressions.Expression<Func<MyType, _>>>