diff --git a/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseOrganisationRepository.cs b/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseOrganisationRepository.cs index 4ab0a56ba..cb41364eb 100644 --- a/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseOrganisationRepository.cs +++ b/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseOrganisationRepository.cs @@ -15,6 +15,7 @@ public void Dispose() return await context.Organisations .Include(p => p.Addresses) .ThenInclude(p => p.Address) + .AsSingleQuery() .FirstOrDefaultAsync(t => t.Guid == organisationId); } @@ -23,6 +24,7 @@ public void Dispose() return await context.Organisations .Include(p => p.Addresses) .ThenInclude(p => p.Address) + .AsSingleQuery() .FirstOrDefaultAsync(t => t.Name == name); } public async Task> FindOrganisationPersons(Guid organisationId) @@ -30,6 +32,7 @@ public async Task> FindOrganisationPersons(Guid return await context.Set() .Include(op => op.Person) .Where(op => op.Organisation.Guid == organisationId) + .AsSingleQuery() .ToListAsync(); } @@ -51,6 +54,7 @@ public async Task> FindByUserUrn(string userUrn) .Include(p => p.Organisations) .ThenInclude(p => p.Addresses) .ThenInclude(p => p.Address) + .AsSingleQuery() .FirstOrDefaultAsync(p => p.UserUrn == userUrn); return person?.Organisations ?? []; } @@ -61,6 +65,7 @@ public async Task> FindByUserUrn(string userUrn) .Include(p => p.Identifiers) .Include(p => p.Addresses) .ThenInclude(p => p.Address) + .AsSingleQuery() .FirstOrDefaultAsync(o => o.Identifiers.Any(i => i.Scheme == scheme && i.IdentifierId == identifierId)); } @@ -84,7 +89,7 @@ public async Task> Get(string? type) break; } - return await result.ToListAsync(); + return await result.AsSingleQuery().ToListAsync(); } public async Task> GetConnectedIndividualTrusts(int organisationId) @@ -94,7 +99,7 @@ public async Task> GetConnectedIndividualTrusts(int organ .Where(x => x.IndividualOrTrust != null && x.EntityType == ConnectedEntity.ConnectedEntityType.Individual) .Where(x => x.SupplierOrganisation != null && x.SupplierOrganisation.Id == organisationId); - return await result.ToListAsync(); + return await result.AsSingleQuery().ToListAsync(); } public async Task> GetConnectedOrganisations(int organisationId) @@ -104,7 +109,7 @@ public async Task> GetConnectedOrganisations(int organisa .Where(x => x.Organisation != null && x.EntityType == ConnectedEntity.ConnectedEntityType.Organisation) .Where(x => x.SupplierOrganisation != null && x.SupplierOrganisation.Id == organisationId); - return await result.ToListAsync(); + return await result.AsSingleQuery().ToListAsync(); } public async Task> GetConnectedTrustsOrTrustees(int organisationId) @@ -114,7 +119,7 @@ public async Task> GetConnectedTrustsOrTrustees(int organ .Where(x => x.IndividualOrTrust != null && x.EntityType == ConnectedEntity.ConnectedEntityType.TrustOrTrustee) .Where(x => x.SupplierOrganisation != null && x.SupplierOrganisation.Id == organisationId); - return await result.ToListAsync(); + return await result.AsSingleQuery().ToListAsync(); } public async Task GetLegalForm(int organisationId) @@ -134,6 +139,7 @@ public async Task> GetOperationTypes(int organisationId) var organisation = await context.Organisations .Where(x => x.Id == organisationId) .Include(x => x.SupplierInfo) + .AsSingleQuery() .FirstOrDefaultAsync(); return organisation?.SupplierInfo?.OperationTypes ?? [];