If I have 4 thousand documents (maybe quite a few more, haven't checked) I can use a Func<T,bool>
in IDocumentSession.Query<T>().Where(...)
and I get the expected results. But if I have 800 thousand documents then I have to use an Expression<Func<T,bool>>
, otherwise I get no results.
Why is this not consistent?
The issue is that I have the same predicate used for an in-memory filter as well as a database query filter. For the in-memory filter the collection is IEnumerable<T>
so it uses a Func<T,bool>
whereas for the database query the collection is an IQueryable<T>
so it uses an Expression<Func<T,bool>>
. So in my production code I have an overloaded "filter" method - one that takes an IEnumerable<T>
and another that takes an IQueryable<T>
. Content of the former is: return list.Where(getPredicate(x).Compile())
and content of the latter is: return list.Where(getPredicate(x))
Obviously this just looks like duplicated code and is shouting out: "Please refactor me and reduce the code duplication". But as soon as a developer does that it should break a unit test. However, I can't get a unit test to fail when passing a Func<T,bool>
.
Edit: Upon closer inspection, it appears that it has nothing to do with the number of documents. If I connect to the same "production" database in my unit test (calling the actual production code), it returns results when using Func<T,bool>
but when I run the application it returns nothing. Very strange!