Starts in:
1 DAY
21 HRS
5 MIN
16 SEC
Starts in:
1 D
21 H
5 M
16 S
Open Closed

MongoDb UnitOfWork #6759


User avatar
0
DominaTang created

With code below, at the second unit of work section, the line var dbData = repository.GetAsync(inserted.Id); throw exception, there is no Such Entity? Though if check database later, the new record is inserted into database successfully. Does Mongo driver cache the data somewhere?

[UnitOfWork(IsDisabled = true)]
public async Task SubmitAsync(XXXinput dto)
{
    using var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true);
   //Map dto to Domain entity
   var inserted = await repository.InsertAysnc(domainEntity);
    await uow.SaveChangesAsync();
    await uow.CompleteAsync();

   using var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true);
   var dbData =  repository.GetAsync(inserted.Id);
   //Other db operation
 await uow.SaveChangesAsync();
    await uow.CompleteAsync();
}
  • ABP Framework version: v7.2.3
  • UI Type: Angular / MVC / Blazor WASM / Blazor Server
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..) / MongoDB
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

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

    hi

    Though if check database later, the new record is inserted into database successfully.

    Is the id in the database same as the inserted.Id ?

    You can set a breakpoint here to check the database to see if the record exists.

  • User Avatar
    0
    DominaTang created

    Inserted does return Id, line var dbData = repository.GetAsync(inserted.Id); throw exception, can not find entity with Id xxxxx in log, and that guid value is the Guid in MongoDb.

  • User Avatar
    0
    DominaTang created

    It looks like use .InsertAysnc(entity,true) resolved the problem.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06