Open Closed

How to get username from CreatorId column value ? #2704


User avatar
0
sateesh@g1.com.my created
  • ABP Framework version: v4.2.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

How to get username from CreatorId for all records at a time ? Is there any sample code ?


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    if I understand correctly, are you looking for something like this?

    private readonly IRepository<IdentityUser, Guid> _identityUserRepository;
    
    public async Task GetUserNamesByCreatorId()
    {
        var userNames= (await _identityUserRepository.GetListAsync(x => x.CreatorId == ...)).Select(x => x.UserName);
    }
    
  • User Avatar
    -1
    sateesh@g1.com.my created

    Hi,

    if I understand correctly, are you looking for something like this?

    private readonly IRepository<IdentityUser, Guid> _identityUserRepository; 
     
    public async Task GetUserNamesByCreatorId() 
    { 
        var userNames= (await _identityUserRepository.GetListAsync(x => x.CreatorId == ...)).Select(x => x.UserName); 
    } 
    

    Yes, but i need to get all records Creator name with single query execution

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You need to custom a repository.

    public class MyIdentityUserRepository : EfCoreRepository<IIdentityDbContext, IdentityUser, Guid>, IMyIdentityUserRepository
    {
        //.....
    
        public async Task GetCreatorNamesAsync(Guid creatorId)
        {
            var dbContext = await GetDbContextAsync();
        
            var creatorNames = await (from creator in dbContext.Set<IdentityUser>()
                join user in dbContext.Set<IdentityUser>() on creator.Id equals user.CreatorId
                where user.CreatorId == creatorId
                select creator.Name).ToListAsync();
        }
    }
    
Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11