Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapperly has issue with circular reference for Application user #811

Closed
stratusaxarlis opened this issue Jan 4, 2025 · 1 comment · Fixed by #812
Closed

Mapperly has issue with circular reference for Application user #811

stratusaxarlis opened this issue Jan 4, 2025 · 1 comment · Fixed by #812

Comments

@stratusaxarlis
Copy link

the mapping with mapperly in the solution , named : public static partial class ApplicationUserMapper
cannot create correctly the nullable properties createdby , modifiedbuuser , superior . for single or Projected Iquerable values.

If you check the autogen file is using the same parent properties for createdby , modifiedbuuser , superior .
so even though you change it and its saved correctly in the database and the IQuerable returns correct data the mapper ignores completely the navigation property and maps the parent again i tried all walk arounds as mapperly suggests nothing worked .
ended do a typical and fast extension :

` public static IQueryable ProjectTo(this IQueryable q)
{

        return Queryable.Select(
         q,
         x => new ApplicationUserDto()
         {
             Id = x.Id.ToString(),
             UserName = x.UserName ?? "",
             DisplayName = x.DisplayName,
             Provider = x.Provider,
             TenantId = x.TenantId,
             Tenant = x.Tenant != null ? TenantMapper.ToDto(x.Tenant) : default,
             ProfilePictureDataUrl = x.ProfilePictureDataUrl,
             Email = x.Email ?? "",
             PhoneNumber = x.PhoneNumber,
             SuperiorId = x.SuperiorId != null ? x.SuperiorId.Value.ToString() : default,
             Superior = x.Superior != null ? new ApplicationUserDto()
             {
                 Id = x.Superior.Id.ToString(),
                 UserName = x.Superior.UserName ?? "",
                 DisplayName = x.Superior.DisplayName,
                 Provider = x.Superior.Provider,
                 TenantId = x.Superior.TenantId,
                 Tenant = x.Superior.Tenant != null ? TenantMapper.ToDto(x.Superior.Tenant) : default,
                 ProfilePictureDataUrl = x.Superior.ProfilePictureDataUrl,
                 Email = x.Superior.Email ?? "",
                 PhoneNumber = x.Superior.PhoneNumber,
                 SuperiorId = x.Superior.SuperiorId != null ? x.Superior.SuperiorId.Value.ToString() : default,
                 IsActive = x.Superior.IsActive,
                 IsLive = x.Superior.IsLive,
                 EmailConfirmed = x.Superior.EmailConfirmed,
                 LockoutEnd = x.Superior.LockoutEnd,
                 TimeZoneId = x.Superior.TimeZoneId,
                 LanguageCode = x.Superior.LanguageCode,
                 LastModified = x.Superior.LastModified,
                 LastModifiedBy = x.Superior.LastModifiedBy != null ? x.Superior.LastModifiedBy.Value.ToString() : default,
                 Created = x.Superior.Created,
                 CreatedBy = x.Superior.CreatedBy != null ? x.Superior.CreatedBy.Value.ToString() : default,
             }: null,
             AssignedRoles = Enumerable.ToArray(Enumerable.Select(x.UserRoles, r => r.Role.Name!)),
             IsActive = x.IsActive,
             IsLive = x.IsLive,
             EmailConfirmed = x.EmailConfirmed,
             LockoutEnd = x.LockoutEnd,
             TimeZoneId = x.TimeZoneId,
             LanguageCode = x.LanguageCode,
             LastModified = x.LastModified,
             LastModifiedBy = x.LastModifiedBy != null ? x.LastModifiedBy.Value.ToString() : default,
             Created = x.Created,
             CreatedBy = x.CreatedBy != null ? x.CreatedBy.Value.ToString() : default,
             CreatedByUser = x.CreatedByUser != null ?  new ApplicationUserDto()
             {
                 Id = x.CreatedByUser.Id.ToString(),
                 UserName = x.CreatedByUser.UserName ?? "",
                 DisplayName = x.CreatedByUser.DisplayName,
                 Provider = x.CreatedByUser.Provider,
                 TenantId = x.CreatedByUser.TenantId,
                 Tenant = x.CreatedByUser.Tenant != null ? TenantMapper.ToDto(x.CreatedByUser.Tenant) : default,
                 ProfilePictureDataUrl = x.ProfilePictureDataUrl,
                 Email = x.CreatedByUser.Email ?? "",
                 PhoneNumber = x.CreatedByUser.PhoneNumber,
                 SuperiorId = x.CreatedByUser.SuperiorId != null ? x.CreatedByUser.SuperiorId.Value.ToString() : default,
                 IsActive = x.CreatedByUser.IsActive,
                 IsLive = x.CreatedByUser.IsLive,
                 EmailConfirmed = x.CreatedByUser.EmailConfirmed,
                 LockoutEnd = x.CreatedByUser.LockoutEnd,
                 TimeZoneId = x.CreatedByUser.TimeZoneId,
                 LanguageCode = x.CreatedByUser.LanguageCode,
                 LastModified = x.CreatedByUser.LastModified,
                 LastModifiedBy = x.CreatedByUser.LastModifiedBy != null ? x.CreatedByUser.LastModifiedBy.Value.ToString() : default,
                 Created = x.CreatedByUser.Created,
                 CreatedBy = x.CreatedByUser.CreatedBy != null ? x.CreatedByUser.CreatedBy.Value.ToString() : default,
             }: null,
             LastModifiedByUser = x.LastModifiedByUser != null ? new ApplicationUserDto()
             {
                 Id = x.LastModifiedByUser.Id.ToString(),
                 UserName = x.LastModifiedByUser.UserName ?? "",
                 DisplayName = x.LastModifiedByUser.DisplayName,
                 Provider = x.LastModifiedByUser.Provider,
                 TenantId = x.LastModifiedByUser.TenantId,
                 Tenant = x.LastModifiedByUser.Tenant != null ? TenantMapper.ToDto(x.LastModifiedByUser.Tenant) : default,
                 ProfilePictureDataUrl = x.ProfilePictureDataUrl,
                 Email = x.LastModifiedByUser.Email ?? "",
                 PhoneNumber = x.LastModifiedByUser.PhoneNumber,
                 SuperiorId = x.LastModifiedByUser.SuperiorId != null ? x.LastModifiedByUser.SuperiorId.Value.ToString() : default,
                 IsActive = x.LastModifiedByUser.IsActive,
                 IsLive = x.LastModifiedByUser.IsLive,
                 EmailConfirmed = x.LastModifiedByUser.EmailConfirmed,
                 LockoutEnd = x.LastModifiedByUser.LockoutEnd,
                 TimeZoneId = x.LastModifiedByUser.TimeZoneId,
                 LanguageCode = x.LastModifiedByUser.LanguageCode,
                 LastModified = x.LastModifiedByUser.LastModified,
                 LastModifiedBy = x.LastModifiedByUser.LastModifiedBy != null ? x.LastModifiedByUser.LastModifiedBy.Value.ToString() : default,
                 Created = x.LastModifiedByUser.Created,
                 CreatedBy = x.LastModifiedByUser.CreatedBy != null ? x.LastModifiedByUser.CreatedBy.Value.ToString() : default,
             }: null,
         }
     );

#nullable enable
}
`

Also the modal for update user Superior doesnt work because the modal doesnt do anything besides send notification to blazor for ok. i have fixed it in my solution by updating the model with usermanager .

@neozhu
Copy link
Owner

neozhu commented Jan 4, 2025

Can you submit a pr for this bug?

@neozhu neozhu closed this as completed in 0fb8b81 Jan 5, 2025
neozhu added a commit that referenced this issue Jan 5, 2025
fixed Mapperly has issue with circular reference for Application user #811
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants