From d32e8a090fea734efaaaaa658fcec657a904708c Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 29 Sep 2023 12:11:06 +0800 Subject: [PATCH] Fix possible `null` errors. Resolve #17766 --- .../EfCoreOrganizationUnitRepository.cs | 2 +- .../Identity/MongoDB/MongoOrganizationUnitRepository.cs | 2 +- .../Abp/Identity/OrganizationUnitRepository_Tests.cs | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs index cd2e2af595..9a766ed1c9 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs @@ -40,7 +40,7 @@ public class EfCoreOrganizationUnitRepository { return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) - .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value) + .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId) .ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs index 23726693ad..728696ada8 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs @@ -39,7 +39,7 @@ public class MongoOrganizationUnitRepository CancellationToken cancellationToken = default) { return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value) + .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId) .ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs index be757d5008..9ff41f2385 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs @@ -47,8 +47,13 @@ public abstract class OrganizationUnitRepository_Tests : AbpIden [Fact] public async Task GetAllChildrenWithParentCodeAsync() { - (await _organizationUnitRepository.GetAllChildrenWithParentCodeAsync(OrganizationUnit.CreateCode(0), - _guidGenerator.Create())).ShouldNotBeNull(); + var allChildren = await _organizationUnitRepository.GetAllChildrenWithParentCodeAsync(OrganizationUnit.CreateCode(0), _guidGenerator.Create()); + allChildren.ShouldNotBeNull(); + allChildren.ShouldBeEmpty(); + + allChildren = (await _organizationUnitRepository.GetAllChildrenWithParentCodeAsync(OrganizationUnit.CreateCode(1), null)); + allChildren.ShouldNotBeNull(); + allChildren.ShouldNotBeEmpty(); } [Fact]