Base solution for your next web application
Open Closed

Sorting of multi-lingual entities #6154


User avatar
0
alexanderpilhar created

Please, help me: How do I implement sorting for multi-lingual entities? I have a simple entity that implements IMultiLingualEntity. I just recognized sorting doesn't work (using GetAllPagedSortedAndFilteredInputDto). I tried playing around with pSortableColumn-value but can't figure it out. Is it even possible this way?


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    Could you share your app service code for getting the entity list ?

  • User Avatar
    0
    alexanderpilhar created

    Hi @ismcagdas

    Here's the code.

    public async Task<IPagedResult<CategoryBackendDto>> GetAllPagedSortedAndFilteredAsync(GetAllPagedSortedAndFilteredInputDto input)
    {
        var query = _repCategories
            .GetAllIncluding(e => e.Translations)
            .WhereIf(
                input.IsActive != null,
                e => e.IsActive == input.IsActive
            );
    
        var cntEntities = await query
                .CountAsync();
    
        var lstEntities = await query
            .OrderBy(input.Sorting)
            .PageBy(input)
            .ToListAsync();
    
        return new PagedResultDto<CategoryBackendDto>(
            cntEntities,
            ObjectMapper.Map<List<CategoryBackendDto>>(lstEntities)
        );
    }
    
  • User Avatar
    0
    alexanderpilhar created

    BTW: Sorting works fine for other non-translated columns/properties.

  • User Avatar
    1
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    I don't know if EF supports sorting via a entity collection property. You can check EF's documentation for that. Even if it supports such a feature, I think sorting will be done after retrieving the entire list and it will cause a performance problem.

    We have disabled sorting user list bye role column because of this purpose.

    If you need it, I think it is better to use a raw sql query.

  • User Avatar
    0
    alexanderpilhar created

    I see. Well, thank you for your answer @ismcagdas! I will go with disabling sorting on that column, too (since there is no request for that, yet).

  • User Avatar
    0
    ibtikar created

    Please, help me: How do I implement sorting for multi-lingual entities? We have a title of books which we are storing as arabic and english. Now I want to sort books by title. Help to find a solution.

  • User Avatar
    0
    alexanderpilhar created

    Hi @ibtikar!

    As @ismcagdas already stated you might consider using a raw sql query.