Starts in:
2 DAYS
17 HRS
4 MIN
46 SEC
Starts in:
2 D
17 H
4 M
46 S
Open Closed

Unable to sort extended field of 'FileManagement' module #5693


User avatar
0
gizemozdemir created
  • ABP Framework version: v7.0.3
  • UI Type: Angular
  • Database System: EF Core (SQL Server)

Hello Team, I have extended a 'DirectoryDescriptor' , 'FileDescriptor' entities and their dtos of 'FileManagement' module and added a new string type field ,called as 'TestField'. I have configured both entities and I observed that it works properly. I also mapped EFCore property to hold it as a separate column instead of extraProperties column.

However, I am unable to sort 'TestField' because it gives me the following error: [12:36:14 ERR] No property or field 'TestField' exists in type 'DirectoryDescriptor'

I have seen this issue that mentions a similar problem: https://support.abp.io/QA/Questions/4643/Column-sorts-not-working-in-dependent-module-listings---Blazor-Server

Is this issue fixed on newer versions of the ABP framework. Thank you for your time. Kind Regards, Gizem


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share a simple project to reproduce?

    You can create a new template project, Thanks

    liming.ma@volosoft.com

  • User Avatar
    0
    gizemozdemir created

    Hi Again, I just shared my new template project with you. ( sender: ozdemir.gizem@siemens.com)

    Thank you for your time.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks I will confirm it asap.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://learn.microsoft.com/en-us/ef/core/modeling/shadow-properties#accessing-shadow-properties

    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(EfCoreIdentityUserRepository), typeof(IIdentityUserRepository))]
    public class MyEfCoreIdentityUserRepository : EfCoreIdentityUserRepository
    {
        public MyEfCoreIdentityUserRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
    
        public override async Task<List<IdentityUser>> GetListAsync(
            string sorting = null,
            int maxResultCount = int.MaxValue,
            int skipCount = 0,
            string filter = null,
            bool includeDetails = false,
            Guid? roleId = null,
            Guid? organizationUnitId = null,
            string userName = null,
            string phoneNumber = null,
            string emailAddress = null,
            string name = null,
            string surname = null,
            bool? isLockedOut = null,
            bool? notActive = null,
            bool? emailConfirmed = null,
            bool? isExternal = null,
            DateTime? maxCreationTime = null,
            DateTime? minCreationTime = null,
            DateTime? maxModifitionTime = null,
            DateTime? minModifitionTime = null,
            CancellationToken cancellationToken = default)
        {
            if (sorting == "TestField asc" || sorting == "TestField desc")
            {
                var queryable = (await GetDbSetAsync())
                    .IncludeDetails(includeDetails)
                    .WhereIf(
                        !filter.IsNullOrWhiteSpace(),
                        u =>
                            u.UserName.Contains(filter) ||
                            u.Email.Contains(filter) ||
                            (u.Name != null && u.Name.Contains(filter)) ||
                            (u.Surname != null && u.Surname.Contains(filter)) ||
                            (u.PhoneNumber != null && u.PhoneNumber.Contains(filter))
                    )
                    .WhereIf(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value))
                    .WhereIf(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value))
                    .WhereIf(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName)
                    .WhereIf(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber)
                    .WhereIf(!string.IsNullOrWhiteSpace(emailAddress), x => x.Email == emailAddress)
                    .WhereIf(!string.IsNullOrWhiteSpace(name), x => x.Name == name)
                    .WhereIf(!string.IsNullOrWhiteSpace(surname), x => x.Surname == surname)
                    .WhereIf(isLockedOut.HasValue, x => (x.LockoutEnabled && x.LockoutEnd.HasValue && x.LockoutEnd.Value.CompareTo(DateTime.UtcNow) > 0) == isLockedOut.Value)
                    .WhereIf(notActive.HasValue, x => x.IsActive == !notActive.Value)
                    .WhereIf(emailConfirmed.HasValue, x => x.EmailConfirmed == emailConfirmed.Value)
                    .WhereIf(isExternal.HasValue, x => x.IsExternal == isExternal.Value)
                    .WhereIf(maxCreationTime != null, p => p.CreationTime <= maxCreationTime)
                    .WhereIf(minCreationTime != null, p => p.CreationTime >= minCreationTime)
                    .WhereIf(maxModifitionTime != null, p => p.LastModificationTime <= maxModifitionTime)
                    .WhereIf(minModifitionTime != null, p => p.LastModificationTime >= minModifitionTime);
    
                queryable = sorting.Contains("desc")
                    ? queryable.OrderByDescending(b => EF.Property<string>(b, "TestField"))
                    : queryable.OrderBy(b => EF.Property<string>(b, "TestField"));
    
                return await queryable.PageBy(skipCount, maxResultCount).ToListAsync(GetCancellationToken(cancellationToken));
            }
    
            return await base.GetListAsync(sorting, maxResultCount, skipCount, filter, includeDetails, roleId, organizationUnitId,
                userName, phoneNumber, emailAddress, name, surname, isLockedOut, notActive, emailConfirmed, isExternal,
                maxCreationTime, minCreationTime, maxModifitionTime, minModifitionTime, cancellationToken);
        }
    }
    
    
    
  • User Avatar
    0
    gizemozdemir created

    Thank you maliming. I'll close the issue. Have a nice day.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06