一、概述
ABP实体需继承Entity类,Entity类默认定义了一个int类型的主键属性Id。
二、使用
2.1继承Entity类即可
public class Person : Entity
{
public virtual string Name { get; set; }
}
三、其他
3.1 零碎知识点
- 提供了泛型Entity<T>,可改变Id的类型
- 重写了 equality ﴾==﴿ 操作符用来判断两个实体对象是否相等﴾主要是判断两个实体的 Id主键 是否相等﴿
- 定义了一个 IsTransient﴾﴿方法来检测当前 Id 的值是否与指定的类型的缺省值相等
3.2 接口约定
//实现该接口,当该实体被插入到数据库时, ABP 会自动设置该属性的值为当前时间。
public interface IHasCreationTime
{
DateTime CreationTime { get; set; }
}
//扩展自IHasCreationTime,拥有属性CreatorUserId 并自动设置 属性值为当前用户的 Id
//ABP提供了一个实现该接口的类:CreationAuditedEntity
public interface ICreationAudited : IHasCreationTime
{
long? CreatorUserId { get; set; }
}
//APB 会自动设置这些属性的值
public interface IModificationAudited
{
DateTime? LastModificationTime { get; set; }
long? LastModifierUserId { get; set; }
}
//合并两个接口ICreationAudited, IModificationAudited
//ABP提供了一个实现该接口的类:AuditedEntity
public interface IAudited : ICreationAudited, IModificationAudited
{ }
//实现该接口,不会真正删除,只是标记IsDeleted为删除状态,同时查询时ABP会自动过滤掉
public interface ISoftDelete
{
bool IsDeleted { get; set; }
}
//APB 会自动设置这些属性的值
public interface IDeletionAudited : ISoftDelete
{
long? DeleterUserId { get; set; }
DateTime? DeletionTime { get; set; }
}
//ABP提供了一个实现该接口的类:FullAuditedEntity
public interface IFullAudited : IAudited, IDeletionAudited
{}