Hi

Open and close a session inside your for each loop and you will be fine

On Fri, Oct 30, 2020, 17:46 Hakan karaoğlu <[email protected]> wrote:

> Hi,
>
> I'm using rabbitmq and nhibernate in a .net core project. I run
> asynchronous queries for database operations on some consumers. For
> example, I am sending a single message to the queue, the message is
> processed successfully, but when I send 100 messages, database operations
> start getting errors after a while.
>
> I tested the similar structure as follows. I did database transactions 100
> times in a loop and it didn't give an error. But when I tried it in
> parallel loop, it gave an error like in rabbitmq.
>
> Is this from Nhibernate or is there a different logic? Nhibernate not
> thread-safe?
>
> Sample Code with Error :
>
> Parallel.For(0, 100, async act =>
>             {
>                 var ws = await
> _workspaceRepository.GetWorkspaceByIdAsync(66);
>                 System.Console.WriteLine($"GetWorkspaceByIdAsync :
> {ws.Name}");
>                 var keywords = await
> _workspaceKeywordRepository.GetForbiddenKeywordsByWorkspaceAsync(66);
>
> System.Console.WriteLine($"GetForbiddenKeywordsByWorkspaceAsync :
> {keywords.Count}");
>                 var IsforbiddenKeyword = await
> HasForbiddenKeywordAsync(66, "facebook", "instagram");
>                 System.Console.WriteLine($"HasForbiddenKeywordAsync :
> {IsforbiddenKeyword}");
>             });
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nhusers/15a15084-855f-4d1c-9ebd-ea1b62cf9a0cn%40googlegroups.com
> <https://groups.google.com/d/msgid/nhusers/15a15084-855f-4d1c-9ebd-ea1b62cf9a0cn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/CAF8vUGXXirEF3Pa6W58scKMLu_iU%2B7Z79Op6y%3DjTTxCwLO%2B%2BVw%40mail.gmail.com.

Reply via email to