Fix untranslatable LINQ query in GetSimilarSoftwareAsync

EF Core could not translate OrderBy chained after a conditional Select
that builds two differently-shaped DTOs. Materialize the projection
first, then order client-side.
This commit is contained in:
2026-06-29 19:56:47 +01:00
parent 1242e6993a
commit 78d8dba196

View File

@@ -2593,24 +2593,27 @@ public class SoftwareController(MarechaiContext context, IMemoryCache cache, Use
[HttpGet("/software/{softwareId:ulong}/similar")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
public Task<List<SoftwareSimilarToDto>> GetSimilarSoftwareAsync(ulong softwareId) =>
context.SoftwareSimilarTo
.Where(e => e.SoftwareId == softwareId || e.SimilarSoftwareId == softwareId)
.Select(e => e.SoftwareId == softwareId
? new SoftwareSimilarToDto
{
SoftwareId = softwareId,
SimilarSoftwareId = e.SimilarSoftwareId,
SimilarSoftwareName = e.SimilarSoftware.Name
}
: new SoftwareSimilarToDto
{
SoftwareId = softwareId,
SimilarSoftwareId = e.SoftwareId,
SimilarSoftwareName = e.Software.Name
})
.OrderBy(e => e.SimilarSoftwareName)
.ToListAsync();
public async Task<List<SoftwareSimilarToDto>> GetSimilarSoftwareAsync(ulong softwareId)
{
List<SoftwareSimilarToDto> similar = await context.SoftwareSimilarTo
.Where(e => e.SoftwareId == softwareId || e.SimilarSoftwareId == softwareId)
.Select(e => e.SoftwareId == softwareId
? new SoftwareSimilarToDto
{
SoftwareId = softwareId,
SimilarSoftwareId = e.SimilarSoftwareId,
SimilarSoftwareName = e.SimilarSoftware.Name
}
: new SoftwareSimilarToDto
{
SoftwareId = softwareId,
SimilarSoftwareId = e.SoftwareId,
SimilarSoftwareName = e.Software.Name
})
.ToListAsync();
return similar.OrderBy(e => e.SimilarSoftwareName).ToList();
}
[HttpGet("/software/{softwareId:ulong}/attributes")]
[AllowAnonymous]