【问题标题】:service.CreateAsync() always returns Id as 0 in ABPservice.CreateAsync() 在 ABP 中总是返回 ID 为 0
【发布时间】:2022-10-16 21:25:53
【问题描述】:

我正在使用 ABP Suite 生成的实体。有时我需要插入实体的Id。但是当调用CreateAsync 方法时,它返回0。它在内部调用InsertAsync 而不是InsertAndGetIdAsync。那么有什么方法可以从保存的实体中映射 Id 吗?

这是代码:

   [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);
   } 

【问题讨论】:

  • 你能分享你的代码吗?
  • 插入后尝试使用SaveChangesAsync()
  • @AhmadMasoum 我尝试使用 SaveChangesAsync() 但 Id 仍然返回为 0

标签: abp aspnetzero


【解决方案1】:

您忘记了代码中的“等待”关键字:

  await UnitOfWorkManager.Current.SaveChangesAsync();

你能再试一次吗?

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

【讨论】:

  • 哦,是的,我错过了。现在它起作用了。谢谢你拯救了我的一天!!
猜你喜欢
  • 2021-11-24
  • 2010-11-24
  • 2021-01-24
  • 1970-01-01
  • 2019-02-27
  • 2013-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多