Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Load CreatorUserName in Get List Entity Data #4499


User avatar
0
ramezani583 created

Hi, I would like to show the creatorusername in UI If i define " public string CreatorUserName { get; set; }" in EntityListDto is enough? Will object-mapper it automatically do this?

public class ProvinceListDto : EntityDto<long>, IHasCreationTime
    {
        public string Name { get; set; }
        public DateTime CreationTime { get; set; }
        public string CreatorUserName { get; set; }
        public bool IsDeleted { get; set; }
      
    }

public async Task<PagedResultDto<ProvinceListDto>> GetProvinces(GetProvincesInput input)
        {
            var query = _provinceRepository
                .GetAll()
                .WhereIf(
                    !input.Filter.IsNullOrWhiteSpace(),
                    p =>
                        p.Name.Contains(input.Filter)
                );
            var provinceCount = await query.CountAsync();

            var provinces = await query
                .OrderBy(input.Sorting)
                .PageBy(input)
                .ToListAsync();

            var provinceListDtos = ObjectMapper.Map<List<ProvinceListDto>>(provinces);

            return new PagedResultDto<ProvinceListDto>(
                provinceCount,
                provinceListDtos
                );
        }

3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Are you using EF Core? If yes, then you need to use GetAllIncluding for CreatorUser:

    var query = _provinceRepository
        .GetAllIncluding(p => p.CreatorUser)
        // ...
    

    AutoMapper will handle the mapping.

    Note:

    • CreatorUserName will be CreatorUser's Name.
    • CreatorUserUserName will be CreatorUser's UserName.
  • User Avatar
    0
    ramezani583 created

    hi, it's work, but i force to change Provinces entity to this:

    namespace SSoft.ResourceAssessmentsNetwork.BasicInfo.Provinces { [Table("Provinces", Schema = "cmn")] public class Province : FullAuditedEntity { public const int MaxNameLength = 32; [Required] [MaxLength(MaxNameLength)] public virtual string Name { get; set; } [ForeignKey("CreatorUserId")] public virtual Authorization.Users.User CreatorUserName { get; set; } } }

    Did I do the right thing?

  • User Avatar
    0
    aaron created
    Support Team

    You can inherit FullAuditedEntity<int, User> instead.