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)
-
0
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.
-
0
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?
-
0
You can inherit FullAuditedEntity<int, User> instead.