Skip to content

Instantly share code, notes, and snippets.

@aodendaal
Created June 1, 2018 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodendaal/86fedc36b3593a4adbd4e35ef0327702 to your computer and use it in GitHub Desktop.
Save aodendaal/86fedc36b3593a4adbd4e35ef0327702 to your computer and use it in GitHub Desktop.
ASP.NET Boilerplate entity not found exception
using System;
namespace Abp.AppFactory
{
public class AbpEntityNotFoundException : Exception
{
private string field;
private string value;
private string entityType;
public override string Message
{
get
{
if (field == null && value == null)
{
return $"Entity '{entityType}' not found";
}
else if (field == null)
{
return $"Entity '{entityType}' with Id '{value}' not found";
}
else
{
return $"Entity '{entityType}' with '{field}' = '{value}' not found";
}
}
}
public AbpEntityNotFoundException(Type entityType)
{
this.entityType = entityType.Name;
}
public AbpEntityNotFoundException(Type entityType, long id)
{
this.entityType = entityType.Name;
this.value = id.ToString();
}
public AbpEntityNotFoundException(Type entityType, string propertyName, string value)
{
this.entityType = entityType.Name;
this.field = propertyName;
this.value = value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment