From 3fe584f8f58483bc14eb14edb191fbe483d00103 Mon Sep 17 00:00:00 2001 From: Ahmet Date: Wed, 8 Apr 2020 13:47:26 +0300 Subject: [PATCH] queryOrder updated --- .../EntityFrameworkCore/EfCoreAuditLogRepository.cs | 8 ++++++-- .../Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs | 7 +++++-- .../Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) 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 0e127ba671..06dcf8ffed 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 @@ -196,11 +196,15 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore public virtual async Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName) { - var query = DbContext.Set().AsNoTracking().IncludeDetails().Where(x => x.EntityId == entityId && x.EntityTypeFullName == entityTypeFullName).OrderBy(x => x.ChangeTime); + var query = DbContext.Set() + .AsNoTracking() + .IncludeDetails() + .Where(x => x.EntityId == entityId && x.EntityTypeFullName == entityTypeFullName); return await (from e in query join auditLog in DbSet on e.AuditLogId equals auditLog.Id - select new EntityChangeWithUsername() {EntityChange = e, UserName = auditLog.UserName}).ToListAsync(); + select new EntityChangeWithUsername() {EntityChange = e, UserName = auditLog.UserName}) + .OrderByDescending(x => x.EntityChange.ChangeTime).ToListAsync(); } protected virtual IQueryable GetEntityChangeListQuery( 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 eaa5146d24..e2f21bfe24 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 @@ -206,8 +206,11 @@ namespace Volo.Abp.AuditLogging.MongoDB public virtual async Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName) { - var auditLogs = await GetMongoQueryable().Where(x => - x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)).As>().OrderBy(x => x.ExecutionTime).ToListAsync(); + var auditLogs = await GetMongoQueryable() + .Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)) + .As>() + .OrderByDescending(x => x.ExecutionTime) + .ToListAsync(); var entityChanges = auditLogs.SelectMany(x => x.EntityChanges).ToList(); diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs index 68c56bf5a7..3214ee75af 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs @@ -984,7 +984,7 @@ namespace Volo.Abp.AuditLogging await AuditLogRepository.GetEntityChangeWithUsernameAsync(entityChanges.First().Id); entityHistory.EntityChange.ChangeTime.ShouldBe(entityChanges.First().ChangeTime); - entityHistory.UserName.ShouldNotBeNull();; + entityHistory.UserName.ShouldNotBeNull(); } } }