You can use IDbCommandInterceptor to intercept all calls in the database. Then trim any parameters passed.
See this article for more details and especially how to register an interceptor.
class TrimCommandInterceptor: IDbCommandInterceptor { public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> ctx) { foreach (var p in command.Parameters) { if (p.Value is string) p.Value = ((string) p.Value).Trim(); } }
source share