Skip to content

Commit

Permalink
Merge pull request #812 from neozhu/bugfix/applicationusermapper
Browse files Browse the repository at this point in the history
fixed Mapperly has issue with circular reference for Application user #811
  • Loading branch information
neozhu authored Jan 5, 2025
2 parents c5798e1 + 0fb8b81 commit f52ba45
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Riok.Mapperly" Version="4.1.1" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.5.1" />
<PackageReference Include="Hangfire.Core" Version="1.8.17" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.0.0-preview-3" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.0.0-preview-4" />
<PackageReference Include="ActualLab.Fusion" Version="9.8.3" />
<PackageReference Include="ActualLab.Fusion.Blazor" Version="9.8.3" />
<PackageReference Include="ActualLab.Generators" Version="9.8.3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,38 @@ public static partial class ApplicationUserMapper
[MapperIgnoreSource(nameof(ApplicationUser.CreatedByUser))]
[MapperIgnoreSource(nameof(ApplicationUser.LastModifiedByUser))]
[MapperIgnoreSource(nameof(ApplicationUser.Superior))]
[MapperIgnoreSource(nameof(ApplicationUser.Tenant))]
private static partial ApplicationUserDto MapWithoutRelatedProperties(ApplicationUser user);
public static IQueryable<ApplicationUserDto> ProjectTo(this IQueryable<ApplicationUser> q)
{
return q.Select(x => new ApplicationUserDto
{
Id = x.Id,
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,
Superior = x.Superior != null ? MapWithoutRelatedProperties(x.Superior) : null,
CreatedByUser = x.CreatedByUser != null ? MapWithoutRelatedProperties(x.CreatedByUser) : null,
LastModifiedByUser = x.LastModifiedByUser != null ? MapWithoutRelatedProperties(x.LastModifiedByUser) : null,
AssignedRoles = x.UserRoles.Select(r => r.Role.Name!).ToArray(),
IsActive = x.IsActive,
IsLive = x.IsLive,
EmailConfirmed = x.EmailConfirmed,
LockoutEnd = x.LockoutEnd,
TimeZoneId = x.TimeZoneId,
LanguageCode = x.LanguageCode,
LastModified = x.LastModified,
LastModifiedBy = x.LastModifiedBy,
Created = x.Created,
CreatedBy = x.CreatedBy
});
}

public static partial IQueryable<ApplicationUserDto> ProjectTo(this IQueryable<ApplicationUser> q);

private static string[] MapAssignedRoles(ICollection<ApplicationUserRole> roles)
{
Expand Down

0 comments on commit f52ba45

Please sign in to comment.