service.CreateAsync() always returns Id as 0 in ABP

293 views Asked by At

I'm using generated entities from ABP Suite. Sometimes I need Id of inserted entity. But when CreateAsync method is called it returns 0. It internally calls InsertAsync and not InsertAndGetIdAsync. So is there any way to map Id from saved entity?

Here's the code:

   [Authorize(BrianPermissions.LabRequirements.Create)]
   public virtual async Task<LabRequirementDto> CreateAsync(
        LabRequirementCreateDto input)
   {
        var LabRequirement = await _LabRequirementManager.CreateAsync(
         input.TechQualification, 
         input.TechExperience, 
         input.Equipments, 
         input.Others);
       UnitOfWorkManager.Current.SaveChangesAsync();

       return ObjectMapper.Map<LabRequirement, LabRequirementDto>(LabRequirement);
   } 
1

There are 1 answers

0
Kalves On BEST ANSWER

You forget 'await' keyword in your code:

  await UnitOfWorkManager.Current.SaveChangesAsync();

Can you try again ?

See: https://docs.abp.io/en/abp/latest/Unit-Of-Work#savechangesasync