BeforeExecFilter not executed for ExecuteSqlAsync and QueryAsync

I am currently using ServiceStack 5.1.0

I have setup delegates for the following OrmLiteConfig Actions:

BeforeExecFilter
SqlExpressionSelectFilter

I have also created a ExecFilter that overrides the Exec operation.

The delegates and Exec operation are executed as expected for ‘most’ ORMLite extensions. However, when we use ‘ExecuteSqlAsync’ to execute raw SQL or we use the Dapper extension ‘QueryAsync’ the delegates and Exec operation are never invoked. Is this by design? If so, could you please recommend a way to globally capture the SQL prior to its execution?

Thank you

The Dapper included in OrmLite is the stock Dapper code from the Dapper connection, it has no connection with OrmLite other than both add extension methods over IDbConnection so you can easily access features in each ORM when you need to.

You can use ExequteSqlAsync or async API versions like SqlListAsync, SqlScalarAsync, etc to execute custom SQL in OrmLite.

You can’t capture Dapper SQL unless you use a DB Profiler like in Mini Profiler or a SQL Profiler for your database.

I appreciate the quick response. Quite frankly, your response time is unparalleled.

This explains why we are seeing the described behavior when using the Dapper extensions. However, when we use the ‘ExecuteSqlAsync’ extension, the delegates associated with OrmLiteConfig.BeforeExecFilter and OrmLiteConfig.SqlExpressionSelectFilter are not being invoked.

Is this by design? Or does it need to be configured differently when using these extensions?

Thank you

Nope not by design, just an omission which is resolved with this commit.

This change is available from v5.1.1 that’s now available on MyGet.

Again, we appreciate the quick response.

Please note: The behavior is also exhibited when using the SqlListAsync extension method.

We have not tested the SqlScalarAsync extension method.

Are you testing this with the latest v5.1.1 on MyGet? If you already had v5.1.1 installed you will need to clear your NuGet cache.

I’ve tested SqListAsync and it calls the same ExecReaderAsync() API which I’ve just resolved.

If it’s still an issue with v5.1.1 on MyGet please provide a stand-alone example that doesn’t call the filter.

I now have the latest and the expected behavior is observed.

Your time and effort is appreciated.

1 Like