Expression tree parsing gets to be a complex thing, and I'm not really sure EXACTLY what's going on, although I'm not sure your posted code is exactly right as in the IsSpam()
implementation, I'm not really sure how the r
parameter would get in there, as it's written now.
It might have to do with the closure created in the first example and how external values could leak into it, while the second example as a Func
is more explicit which wouldn't allow those crazy closure things to happen.
Regardless, the point of Raven's LINQ provider is to take the expression tree provided and ship it to the server and have the server able to convert it into Lucene query syntax. Like all abstractions, it leaks, so not everything is possible, but generally simpler things are going to work better than complex or roundabout things.
Instead of using the DateTime's Subtract method, it might work better to use standard operators:
RavenSession.Query<R>().Any(x => (DateTime.Now - x.Submitted).TotalSeconds < 61)
The expression tree created by that would be much different (and probably easier to parse) than your first one, I would expect.
Also, I have to add, be careful using DateTime.Now in your queries. The value will obviously be different every single time you run the query, so you will never be able to take advantage of the Raven client's ability to cache results.