MongoDB - Why can't compiled Func<> with function call be used with MongoQueryable?
<p>I'm trying to write a generic search function for MongoDB.  I put together a Func&lt;> using a method that accepts the target of the lambda and returns back the value of the named property for that target.</p>

<pre><code>case QueryType.BetweenExclusive:
    if (values.Length &lt; 2)
        throw new ArgumentOutOfRangeException(nameof(values),
            "Must supply at least two values for Between comparisons.");
    var ve1 = DateTimeOffset.Parse(values[0].ToString());
    var ve2 = DateTimeOffset.Parse(values[1].ToString());

    exp =
        x =&gt;
            GetDateTimeOffset(x, field) &gt; ve1 &amp;&amp;
            GetDateTimeOffset(x, field) &lt; ve2;

    filter = exp.Compile();

    break;
</code></pre>

<p><code>GetDateOffset</code> is defined as:</p>

<pre><code>    public DateTimeOffset GetDateTimeOffset(PageHitDE x, string field)
    {
        return x.GetValue&lt;DateTimeOffset&gt;(field, new object[0], BindingFlags.Public | BindingFlags.Instance);
    }
</code></pre>

<p>Finally, the <code>GetValue</code> extension method is defined in [<a href="https://github.com/sharpninja/GenericExtensionMethods/blob/master/ReflectionExtensions.cs]" rel="nofollow">https://github.com/sharpninja/GenericExtensionMethods/blob/master/ReflectionExtensions.cs]</a>.  </p>

<p>The compiled Func&lt;> is used like this:</p>

<pre><code>results.AddRange(_proxy.Get&lt;PageHitDE&gt;(x =&gt; filter(x)));
</code></pre>

<p><code>results</code> is an IList defined elsewhere.  Get&lt;> is define as:</p>

<pre><code>    public IQueryable&lt;T&gt; Get&lt;T&gt;(Expression&lt;Func&lt;T, Boolean&gt;&gt; predicate)
    {
        String collectionName = typeof(T).Name;
        IMongoCollection&lt;T&gt; collection = Database.GetCollection&lt;T&gt;(collectionName);
        return MongoQueryable.Where(collection.AsQueryable(), predicate).AsQueryable();
    }
</code></pre>

<p>I really, really, really need to get this working.  I don't understand why a compiled function would not be acceptable to MongoQueryable.</p>