实体历史记录在aspnetboilerplate中不起作用

时间:2020-05-04 13:33:23

标签: aspnetboilerplate

我正在使用aspnetboilerplate,并在模块中的preintiliaze中添加了以下配置。我还向我的实体添加了数据注释“已审计”,但仍然无法正常工作。我的实体是从AuditedEntity继承的,因为不需要删除功能。请帮忙

Configuration.EntityHistory.IsEnabled = true; Configuration.EntityHistory.Selectors.Add(new NamedTypeSelector(“ Abp.AuditedEntities”,type => typeof(AuditedEntity).IsAssignableFrom(type)))

我已从此处引用Can't enable Entity History in ASP.NET Zero 下面是实体定义

[Audited]
public partial class QuestionResponse : AuditedEntity<long>
{
    public long ApplicationId { get; set; }
    public long QuestionId { get; set; }
    public string Response { get; set; }
    public string Remark { get; set; }
    public bool IsActive { get; set; }

    public Application Application { get; set; }
    public AbpUsers CreatorUser { get; set; }
    public AbpUsers LastModifierUser { get; set; }
    public Question Question { get; set; }
} 

1 个答案:

答案 0 :(得分:0)

AuditedEntity<long>不可分配给AuditedEntity

改为根据接口IAuditedEntity添加选择器。

Configuration.EntityHistory.Selectors.Add(
    new NamedTypeSelector("Abp.AuditedEntities", type => 
     // typeof(AuditedEntity).IsAssignableFrom(type)));
        typeof(IAuditedEntity).IsAssignableFrom(type)));

参考

来自aspnetboilerplate/aspnetboilerplate's AuditedEntity.cs

public abstract class AuditedEntity : AuditedEntity<int>, IEntity
{
}

public abstract class AuditedEntity<TPrimaryKey> : CreationAuditedEntity<TPrimaryKey>, IAudited
{
    ...
}