Hello, I am wondering if it is possible to gain access to the result set at some level outside of where a linq query is written. For example, I can monitor the queries that are written via the Log property of the DataContext but have so far been unable to identify a way of capturing the query results. My hope was to extend DataContext and override the 'ExecuteQuery' methods and capture the IQueryable there, afterwards calling ToList(), but unfortunately the methods are all non-virtual.
The motivation behind this is to capture the queries and results and store them in a serialized fashion for later replay.
Perhaps there is some monitor that I can use? I noticed the DbMonitor class but it wasn't obvious to me if this could be used.
Capture SQL execution results
Re: Capture SQL execution results
We can set virtual modifier to the DataProvider.Execute overload with the Expression parameter:charliemango wrote:My hope was to extend DataContext and override the 'ExecuteQuery' methods and capture the IQueryable there, afterwards calling ToList(), but unfortunately the methods are all non-virtual.
Code: Select all
protected virtual IExecuteResult Execute(Expression query)
Does this approach suit your scenario? If so, please confirm your request.
-
- Posts: 2
- Joined: Tue 29 Nov 2016 10:23
Re: Capture SQL execution results
I have managed to find a roundabout solution involving wrapping Queryable and QueryProvider objects and capturing the DataContext.Log at query execution time. It's a bit messy, your solution sounds better.
I am using Devart.Data.Oracle.Linq, Version=4.2.292.0 and I don't see this Execute method defined in Devart.Data.Oracle.Linq.Provider.OracleDataProvider or Devart.Data.Linq.DataProvider. Can you direct me here? If all query execution gets passed through this method then it would be a much more convenient approach.
On a related note, is there a way to get access to the generated SQL at that point other than via the Log property? I ask because the SQL I catch via DataContext.Log is formatted with parameters as SQL comments and I don't see any way to override this formatting.
I am using Devart.Data.Oracle.Linq, Version=4.2.292.0 and I don't see this Execute method defined in Devart.Data.Oracle.Linq.Provider.OracleDataProvider or Devart.Data.Linq.DataProvider. Can you direct me here? If all query execution gets passed through this method then it would be a much more convenient approach.
On a related note, is there a way to get access to the generated SQL at that point other than via the Log property? I ask because the SQL I catch via DataContext.Log is formatted with parameters as SQL comments and I don't see any way to override this formatting.
Re: Capture SQL execution results
1. There is no such a method in a current implementation. Please confirm your request, and we will implement it.charliemango wrote:I am using Devart.Data.Oracle.Linq, Version=4.2.292.0 and I don't see this Execute method defined in Devart.Data.Oracle.Linq.Provider.OracleDataProvider or Devart.Data.Linq.DataProvider. Can you direct me here? If all query execution gets passed through this method then it would be a much more convenient approach.
2. The OracleDataProvider.LogCommand method is called before executing OracleCommand. Do you want to override it?charliemango wrote:On a related note, is there a way to get access to the generated SQL at that point other than via the Log property? I ask because the SQL I catch via DataContext.Log is formatted with parameters as SQL comments and I don't see any way to override this formatting.