Thanks @exlnt & @ismcagdas !
I was able to retrieve the UserName simply by adding CreatorUserUserName to my DTO.
If this object is mapped(?), where is it inherited from? I am trying to understand how the object CreatorUser is created?
Thanks!
I tried something like this. Which populates the query correctly, but then I get mapping errors with my listDto.
var query = from Widget in _WidgetRepository
.GetAll()
.Include(p => p.CreatorUser)
.AsQueryable()
select new
{
Id = Widget.Id,
Priority = Widget.Priority,
UserName = Widget.CreatorUser.UserName,
CreationTime = Widget.CreationTime
};
[AutoMap(typeof(Widget))]
public class WidgetListDto
{
public Guid Id { get; set; }
public int Priority { get; set; }
public DateTime CreationTime { get; set; }
[NotMapped]
public string UserName { get; set; }
}
I am trying to add the Creator UserName to a grid. I can only seem to get the Name. CreatorUserName is the First Name for the APB.User. I am trying to acquire and display the actual UserName for the user that created a record.
Thanks!
public async Task<PagedResultDto<WidgetListDto>> GetWidgets(WidgetFilteredInputDto input)
{
var query = _WidgetRepository
.GetAll()
.Include(p => p.CreatorUser)
.AsQueryable();
var recordCount = await query.CountAsync();
var records = await query
.OrderBy(input.Sorting)
.PageBy(input)
.ToListAsync();
var listDto = records.MapTo<List<WidgetListDto>>();
return new PagedResultDto<WidgetListDto>(
recordCount,
listDto);
}
[AutoMap(typeof(Widget))]
public class WidgetListDto
{
public int Priority { get; set; }
public string CreatorUserName { get; set; }
public DateTime CreationTime { get; set; }
[NotMapped]
[ForeignKey("CreatorUserId")]
public virtual User User { get; set; }
public long CreatorUserId { get; set; }
public string DisplayName
{
get
{
return User.UserName;
}
}
}
}
public class Widget : FullAuditedEntity<Guid, User>
{
[Required]
public virtual int Priority { get; set; }
}