EntityNotFoundException.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Runtime.Serialization;
  3. namespace Abp.Domain.Entities
  4. {
  5. /// <summary>
  6. /// This exception is thrown if an entity excepted to be found but not found.
  7. /// </summary>
  8. [Serializable]
  9. public class EntityNotFoundException : AbpException
  10. {
  11. /// <summary>
  12. /// Type of the entity.
  13. /// </summary>
  14. public Type EntityType { get; set; }
  15. /// <summary>
  16. /// Id of the Entity.
  17. /// </summary>
  18. public object Id { get; set; }
  19. /// <summary>
  20. /// Creates a new <see cref="EntityNotFoundException"/> object.
  21. /// </summary>
  22. public EntityNotFoundException()
  23. {
  24. }
  25. /// <summary>
  26. /// Creates a new <see cref="EntityNotFoundException"/> object.
  27. /// </summary>
  28. public EntityNotFoundException(SerializationInfo serializationInfo, StreamingContext context)
  29. : base(serializationInfo, context)
  30. {
  31. }
  32. /// <summary>
  33. /// Creates a new <see cref="EntityNotFoundException"/> object.
  34. /// </summary>
  35. public EntityNotFoundException(Type entityType, object id)
  36. : this(entityType, id, null)
  37. {
  38. }
  39. /// <summary>
  40. /// Creates a new <see cref="EntityNotFoundException"/> object.
  41. /// </summary>
  42. public EntityNotFoundException(Type entityType, object id, Exception innerException)
  43. : base($"There is no such an entity. Entity type: {entityType.FullName}, id: {id}", innerException)
  44. {
  45. EntityType = entityType;
  46. Id = id;
  47. }
  48. /// <summary>
  49. /// Creates a new <see cref="EntityNotFoundException"/> object.
  50. /// </summary>
  51. /// <param name="message">Exception message</param>
  52. public EntityNotFoundException(string message)
  53. : base(message)
  54. {
  55. }
  56. /// <summary>
  57. /// Creates a new <see cref="EntityNotFoundException"/> object.
  58. /// </summary>
  59. /// <param name="message">Exception message</param>
  60. /// <param name="innerException">Inner exception</param>
  61. public EntityNotFoundException(string message, Exception innerException)
  62. : base(message, innerException)
  63. {
  64. }
  65. }
  66. }