版本260406
This commit is contained in:
51
OrpaonVision.Core/Domain/EntityBase.cs
Normal file
51
OrpaonVision.Core/Domain/EntityBase.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace OrpaonVision.Core.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// 实体基类。
|
||||
/// </summary>
|
||||
public abstract class EntityBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键ID。
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 判断实体是否为临时实体(未持久化)。
|
||||
/// </summary>
|
||||
public bool IsTransient => Id <= 0;
|
||||
|
||||
/// <summary>
|
||||
/// 重写Equals方法。
|
||||
/// </summary>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is null || obj.GetType() != GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj is EntityBase other)
|
||||
{
|
||||
return other.Id == Id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写GetHashCode方法。
|
||||
/// </summary>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写ToString方法。
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType().Name}#{Id}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user