Recommand · December 8, 2021 0

Return Foreign Key Data on Get All Call

I have my unit of measure in the database, when you save a unit, you save the name, id, tenant Id and more to the table, then UnitSize get saved to its own table UnitOfMeasureSize. It shares the UnitOFMeasureId and I need to figure out how to get the the UnitSize back and display it with the UOM name in my accordion, I can do it with raw sql but not sure how to do it in C# using my service. Any suggestions?

here is my dropdown
Accordion dropdown

How I matched it in the Azure Data Studio
Azure Data Studio

     public async Task<IEnumerable<UnitOfMeasureViewModel>> GetAllAsync()
     var result = await _unitOfMeasureRepo.FindByAsync(uom => uom.TenantId == TenantId);
     result.OrderBy(r => r.Name);
     return _mapper.Map<List<UnitOfMeasure>, List<UnitOfMeasureViewModel>>(result.ToList());

Here is how I am trying to grab the Unit Sizes in my AdminStore

   public getUnitSizes(unitOfMeasureId: string) {

     return this.api.get(`/${unitOfMeasureId}/UnitSize`)
            (data: any) => data,
            (error: any) => {throw error;}

public getUnitSizes = async (unitOfMeasureId: string) => {
    const list: any[] = await this.adminAPI.getUnitSizes(unitOfMeasureId);

    runInAction(() => {
        this.unitSizes = list;