2015-09-22 4 views

ответ

8

Вы можете использовать IDbCommandInterceptor для перехвата всех вызовов в базу данных. Затем обрезайте любые передаваемые параметры.

См. this article для более подробной информации и особенно, как зарегистрировать перехватчик.

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(); 
    } 
    } 

    // Add all the other interceptor methods 
}