AuditEntityFieldSet field original value

Posts   
 
    
Posts: 10
Joined: 18-Feb-2024
# Posted on: 18-Feb-2024 01:01:06   

Hi all,

Any idea why am I always getting originalValue as null?

I'm using LLBLGen Pro 5.10 and .NET8

using EduInspection.Data.EntityClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Collections;

namespace EduInspection.Core.Features.Auditing;

[DependencyInjectionInfo(typeof(SchoolGradeEntity), "AuditorToUse")]
[Serializable]
public class SchoolGradeAuditor() : AuditorBase
{
    private enum AuditType
    {
        DeleteOfEntity = 1,
        DirectDeleteOfEntities,
        DirectUpdateOfEntities,
        DereferenceOfRelatedEntity,
        ReferenceOfRelatedEntity,
        EntityFieldSet,
        InsertOfNewEntity,
        UpdateOfExistingEntity
    }

    private List<ActivityLogEntity> _auditInfoEntities = [];

    public override void AuditEntityFieldSet(IEntityCore entity, int fieldIndex, object originalValue)
    {
        var primaryKeyFieldsValues = entity.PrimaryKeyFieldInfos.Select(x => entity.GetCurrentFieldValue(x.FieldIndex));
        var logEntity = new ActivityLogEntity
        {
            EntityName = entity.LLBLGenProEntityName,
            FieldName = entity.Fields.GetFieldNames()[fieldIndex],
            OldValue = originalValue,
            NewValue = entity.GetCurrentFieldValue(fieldIndex).ToString(),
            ActionTypeIndex = (int)AuditType.EntityFieldSet,
            DateCreatedUtc = DateTime.UtcNow,
        };

        _auditInfoEntities.Add(logEntity);
    }
}
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 18-Feb-2024 08:55:01   

If you set an entity field of a new entity, the original value is null.

You have to provide more information regarding when it turns out to be null but you're sure it's not. (e.g. setting an entity field of an existing entity fetched from the db)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 10
Joined: 18-Feb-2024
# Posted on: 18-Feb-2024 10:58:17   

Otis wrote:

If you set an entity field of a new entity, the original value is null.

Yeah, that's it. Thank you!