6
Come rendere Entity Framework automaticamente tagliare tutte le stringhe prima di memorizzarle nel database?Come tagliare la stringa con Entity Framework?
Come rendere Entity Framework automaticamente tagliare tutte le stringhe prima di memorizzarle nel database?Come tagliare la stringa con Entity Framework?
È 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
}