Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Entity Framework - DbUpdateException to a custom Exception
  2. if (e.InnerException.InnerException.Message.Contains("UNIQUE KEY"))
  3. {
  4.      throw new CustomException("message");
  5. }
  6.        
  7. public class DatabaseDataNotFoundException : Exception
  8. {
  9.     public DatabaseDataNotFoundException() : base() { }
  10.  
  11.     public DatabaseDataNotFoundException(string message) : base(message) { }
  12.  
  13.     public DatabaseDataNotFoundException(string message, params object[] args)
  14.         : base(String.Format(CultureInfo.CurrentCulture, message, args)) { }
  15.  
  16.     public DatabaseDataNotFoundException(string message, Exception inner)
  17.         : base(message, inner) { }
  18.  
  19.     public DatabaseDataNotFoundException(string message, Exception inner, params object[] args)
  20.         : base(String.Format(CultureInfo.CurrentCulture, message, args), inner) { }
  21.  
  22.     protected DatabaseDataNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
  23. }
  24.        
  25. if (e.InnerException.InnerException.Message.Contains("UNIQUE KEY"))
  26. {
  27.     throw new DatabaseDataNotFoundException("message");
  28. }