Jul 24 at 9:40 AM
Edited Jul 24 at 10:28 AM
before a query is compiled to sql, all
methods and all
properties are replaced with
. This happens in DbQeuryVisitor, in VisitMethodCall() and VisitMember() methods.
The problem is that the current implementation of this class can perform well, only if the context object is a member. This happens in most common usages of entity framework. However, different usage scenarios are possible:
In our implementation, the client sends expressions to the server, for instance, like:
(Customer customer, IDataContext context) => customer.Invoices.Any(i => context.Set<Goods>().Where(g => g.IsActive).Select(g => g.GoodsId).Contains(i.GoodsId))
(Here, IDataContext is declared in our system, the expression is just made up to help explain the situation)
This is sent to the server and an Expression visitor replaces the context parameter with an actual context object and gets an Expression<Func<Customer, bool>>.
This is fed to Where(Expression<Func<T, bool>>) to filter the results sent to the client.
The problem is that this context object is not a member of any object, just a ConstantExpression. We needed to change The DbQueryVisitor to also support our scenario.
The change is very simple and We'll submit it in a pull request.
If you have any comments or ideas, please let us know
Alireza Haghshenas & Mahdi Farhani