diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs index 9ce2bee070..03051e2655 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -141,9 +142,21 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore return GetQueryable().IncludeDetails(); } - public Task GetEntityChange(Guid entityChangeId) + public virtual async Task GetEntityChange(Guid entityChangeId) { - return DbContext.Set().AsNoTracking().IncludeDetails().OrderBy(x => x.Id).Where(x => x.Id == entityChangeId).FirstAsync(); + var entityChange = await DbContext.Set() + .AsNoTracking() + .IncludeDetails() + .OrderBy(x => x.Id) + .Where(x => x.Id == entityChangeId) + .FirstOrDefaultAsync(); + + if (entityChange == null) + { + throw new EntityNotFoundException(typeof(EntityChange)); + } + + return entityChange; } public virtual async Task> GetEntityChangeListAsync( diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index e2f21bfe24..03f61ca378 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -142,10 +143,17 @@ namespace Volo.Abp.AuditLogging.MongoDB public virtual async Task GetEntityChange(Guid entityChangeId) { - return (await GetMongoQueryable() - .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) - .FirstAsync() - ).EntityChanges.First(x => x.Id == entityChangeId); + var entityChange = (await GetMongoQueryable() + .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) + .FirstAsync()).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); + + + if (entityChange == null) + { + throw new EntityNotFoundException(typeof(EntityChange)); + } + + return entityChange; } public virtual async Task> GetEntityChangeListAsync(