Hi, it does not work either. Won't update count.
hi
Try this:
private async Task UpdateVehicleCount(Guid shipmentId) { using (var uow = this.UnitOfWorkManager.Begin(requiresNew: true)) { var shipment = await this.ShipmentRepository.GetAsync(shipmentId); shipment.VehicleCount = shipment.Vehicles.Count; await this.ShipmentRepository.UpdateAsync(shipment); await uow.CompleteAsync(); } }
hi
Hi, I've tried this and doesn't work.
Can you share a simple project to show that?
Thanks.
liming.ma@volosoft.com
Hi, sorry for the delay. Sent simple project to show it via email.
hi
Can you call the
await UnitOfWorkManager.Current.SaveChangesAsync();
afterDeleteAsync
?eg:
await this.VehicleRepository.DeleteAsync(vehicleId); await UnitOfWorkManager.Current.SaveChangesAsync(); var shipment = await _shipmentRepository.GetAsync(shipmentId); var count = shipment.Vehicles.Count;
Hi, I've tried this and doesn't work. Only work around I have is to add the following which I'd rather not do, which uses what you told me
public class EfCoreShipmentRepository : EfCoreServiceRepository<CoreServiceDbContext, Shipment, Guid>, IShipmentRepository
{
public EfCoreShipmentRepository(IDbContextProvider<CoreServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public override async Task<Shipment> GetAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
await this.UnitOfWorkManager.Current.SaveChangesAsync(cancellationToken);
var dbContext = await this.GetDbContextAsync();
var shipment = await base.GetAsync(id, includeDetails, cancellationToken);
shipment.Vehicles = await dbContext.Vehicles
.Where(x => x.ShipmentId == id)
.ToListAsync(cancellationToken);
return shipment;
}
}