LINQ Line Provider?

I have implemented the simple IQueryable and IQueryProvider classes that collect statistics in LINQ expression trees. This part is working fine. Then I would like to pass the expression tree to the default LINQ to-Objects provider for evaluation, since I don't need to execute it differently. As a word, I would like my provider to collect statistics as a side effect, passing the default LINQ implementation request.

However, it is difficult for me to access the default provider. I thought I could just save the link to the original IEnumerable collection and then return the default provider (from my custom IQueryable ), for example:

 IQueryProvider IQueryable.Provider { get { return _my_provider.OriginalIEnum().AsQueryable().Provider; } } 

but it does not work correctly. The code ultimately throws a StackOverflowException . What I think is happening (gleaned from a single go into debug mode) is that the LINQ runtime extracts the provider from the specified method, then extracts the expression tree from my custom IQueryable , and then notices that the top level expression is my custom IQueryable . So he starts the process again, trying to find the right provider. He does this endlessly until a stack overflow occurs.

For now, the only thing I can come up with is to come up with another visitor who creates another expression tree with the IQueryable user node IQueryable so that the LINQ runtime IQueryable default provider. This is a good job, as I need to visit each sheet to make sure there are no nested Call expressions that my custom IQueryable will call again. Is there a simpler approach?

Thanks for the help.

+6
source share
1 answer

Turns out the real problem here is exactly what is described in passing the LINQ expression to another QueryProvider .

+1
source

Source: https://habr.com/ru/post/946737/


All Articles