2015-09-22 22 views

risposta

8

È possibile utilizzare IDbCommandInterceptor per intercettare tutte le chiamate al database. Quindi taglia tutti i parametri che vengono passati.

Vedere this article per ulteriori dettagli e in particolare come registrare l'intercettore.

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 
} 
Problemi correlati