mirror of
https://github.com/claunia/marechai.git
synced 2026-07-08 17:57:08 +00:00
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:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user