Open Closed

Custom Repo Return Async Result #2667


User avatar
0
OsmanAmanjee created

I have a class which I detail below. Because it has a compisite primary key I cannot use the generic repository. I have created a custom repo to return the records from this entity but I cannot figure out how to return the list as an async result. I've also attached my custom repo interface and class implementation. I'm trying to follow the example from the documentation from this link https://docs.abp.io/en/abp/latest/Repositories, but I'm not able to figure out how to return the result as an async. Please help

public partial class PracticeICD10 : Entity
{
    public int PracticeId { get; set; }
    public int ICD10Id { get; set; }

    public virtual Practice Practice { get; set; }
    public virtual Icd10 ICD10 { get; set; }

    public override object[] GetKeys()
    {
        return new object[] { PracticeId, ICD10Id };
    }
    

public interface IPracticeICD10Repository : IRepository<PracticeICD10>
{
    Task<List<PracticeICD10>> GetPracticeICD10sByPracticeAsync(int practiceId);
}

public class PracticeICD10Repository : EfCoreRepository<MedistatDbContext, PracticeICD10>, IPracticeICD10Repository
{
    public PracticeICD10Repository(IDbContextProvider<MedistatDbContext> dbContextProvider)
        : base(dbContextProvider)
    {

    }

    public async Task<List<PracticeICD10>> GetPracticeICD10sByPracticeAsync(int practiceId)
    {
        var dbContext = await GetDbContextAsync();
        
        return await dbContext.Set<PracticeICD10>()
            .Where(p => p.PracticeId == practiceId).ToList();
    }
}

1 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    You can use GetDbSetAsync

    public async Task<List<PracticeICD10>> GetPracticeICD10sByPracticeAsync(int practiceId)
    {
        return await (await GetDbSetAsync()).ToListAsync();
    } 
    
Made with ❤️ on ABP v9.0.0-preview. Updated on October 07, 2024, 08:52