Base solution for your next web application
Open Closed

Transaction and lazing loading #2410


User avatar
0
jfbaudracco created

Hi,

I don't understand why in the code bellow, the lazing loading (envelope.Sending.SenderId) use a different connection (spid) and this is used until the end of method. So the first GetAsync, begin a transaction with a spid, and the following code, who execute SaveChanges in domain service method, do it with different spid, in a different context. When an exception is raised, the roolback is done for the first context and the SaveChanges is not rolled back.

Someone can help me ? Thank you

/// <summary>
        /// <see cref="ISendingAppService.ConfirmEnvelope(ConfirmEnvelopeInput)"/>.
        /// </summary>
        public async Task ConfirmEnvelope(ConfirmEnvelopeInput input)
        {
            var envelope = await _envelopeRepository.GetAsync(input.Id);

            // Vérification des droits de l'utilisateur qui sollicite la confirmation.
            var permissionName = AppPermissions.Operations_Payslips_Approve; // TODO: implémenter un mécanisme de détermination de l'autorisation en fonction du type d'envoi auquel le pli confirmé est associé.
            if (!(await IsGrantedAsync(envelope.Sending.SenderId.Value, permissionName)))
                throw new AbpAuthorizationException();

            await _sendingManager.ConfirmEnvelopeAsync(envelope);

            if (!input.DemoEmailAddress.IsNullOrWhiteSpace())
                await _envelopeDataRepository.InsertAsync(new EnvelopeData(envelope.Id, EnvelopeDataNames.Demo.EmailAddress, input.DemoEmailAddress));
        }

3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I have created an issue here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1833">https://github.com/aspnetboilerplate/as ... ssues/1833</a>. We will test and fix it, please follow this issue.

    Thanks.

  • User Avatar
    0
    jfbaudracco created

    Hi,

    I found the origin of my problem. I had to add :

    Configuration.ReplaceService<IEfTransactionStrategy, DbContextEfTransactionStrategy>(DependencyLifeStyle.Transient);
    

    in my DataModule. In one of the domain service methods called by the application service method, SaveChangesAsync is invoqued. And, it seems that the transactions are not shared with Ef.

    I do not known if the analyse and solutions are corrects. What do you think about that ?

    Thank you, Jean-François

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @jfbaudracco,

    Yes, your solution is fine. We will also try to solve this problem for the default behaviour.

    Thanks.