By the way, I create as Nhibernate session follows,

public static class SniffactorNHibernateExtension
    {
        public static IServiceCollection AddSniffactorNhibernate(this
IServiceCollection services, string connectionString)
        {
            Check.NotNull(connectionString);

            ISessionFactory _sessionFactory = Fluently.Configure()
                .Database(OracleManagedDataClientConfiguration.Oracle9
                    .ConnectionString(connectionString)
                    .DefaultSchema("IZCI")
                 )

                .Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<ISniffactorMapping>())
                .BuildSessionFactory();

            services.AddSingleton(_sessionFactory);
            services.AddScoped(factory => { return
_sessionFactory.OpenSession(); });
            services.AddScoped(typeof(IRepository<>),
typeof(NhRepositoryBase<>));

            return services;
        }

        private static ISessionFactory BuildSessionFactory(string
connectionString)
        {
            FluentConfiguration configuration = Fluently.Configure()

.Database(OracleManagedDataClientConfiguration.Oracle9.ConnectionString(connectionString).DefaultSchema("IZCI"))
                .Mappings(m => m.FluentMappings
                    .AddFromAssemblyOf<ISniffactorMapping>()
                .Conventions.Add(
                    ConventionBuilder.Property.When(criteria =>
criteria.Expect(x => x.Nullable, Is.Not.Set), x => x.Not.Nullable()))
                .Conventions.Add<OtherConversions>()
                );

            return configuration.BuildSessionFactory();
        }

        private class OtherConversions : IHasManyConvention,
IReferenceConvention
        {
            public void Apply(IOneToManyCollectionInstance instance)
            {
                instance.LazyLoad();
                instance.AsBag();
                instance.Cascade.SaveUpdate();
                instance.Inverse();
            }

            public void Apply(IManyToOneInstance instance)
            {
                instance.LazyLoad(Laziness.Proxy);
                instance.Cascade.None();
                instance.Not.Nullable();
            }
        }
    }

Hakan karaoğlu <[email protected]>, 3 Kas 2020 Sal, 00:59 tarihinde
şunu yazdı:

> Stack trace error and giving "object reference error" as
> follows.Interesting is that the same code works without errors in a normal
> for loop.
>
>  at
> OracleInternal.ServiceObjects.OracleCommandImpl.ExtractAccessorValuesIntoParam(OracleParameterCollection
> paramColl, OracleConnection connection, Int32 paramCount, String
> commandText, Int64 longFetchSize, Int64 clientInitialLOBFS, Int64
> internalInitialLOBFS, Int64[] scnFromExecution, Boolean
> bCallFromExecuteReader)
>    at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean
> requery, Boolean fillRequest, CommandBehavior behavior)
>    at
> Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior
> behavior)
>    at System.Data.Common.DbCommand.ExecuteReader()
>    at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(DbCommand cmd)
>    at NHibernate.Loader.Loader.GetResultSet(DbCommand st, QueryParameters
> queryParameters, ISessionImplementor session, IResultTransformer
> forcedResultTransformer)
>    at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
> QueryParameters queryParameters, Boolean returnProxies, IResultTransformer
> forcedResultTransformer)
>    at
> NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor
> session, QueryParameters queryParameters, Boolean returnProxies,
> IResultTransformer forcedResultTransformer)
>    at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
> QueryParameters queryParameters, IResultTransformer forcedResultTransformer)
>
>
>
> Gunnar Liljas <[email protected]>, 1 Kas 2020 Paz, 03:09 tarihinde
> şunu yazdı:
>
>> What is the error you're getting?
>>
>> On Sat, Oct 31, 2020 at 1:44 AM [email protected] <[email protected]>
>> wrote:
>>
>>> Nhibernate session is not thread safe.
>>>
>>> https://nhibernate.info/doc/nh/en/index.html#transactions
>>>
>>>
>>> On Friday, 30 October 2020 at 12:46:48 UTC-5 [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/09afd1cd-0ef1-44a0-a61a-a3d102c46a7dn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/nhusers/09afd1cd-0ef1-44a0-a61a-a3d102c46a7dn%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/CAAOnFsOOjVYZth2pPOOOcH0uP-EnVrijvmCj1DMb9j7oARMNHQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/nhusers/CAAOnFsOOjVYZth2pPOOOcH0uP-EnVrijvmCj1DMb9j7oARMNHQ%40mail.gmail.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/CAAhRLA349e%2BeE%2B7TL7c-eo%3DUfU4m7hSSKehJFmvVz1Ct-hZ9%2Bg%40mail.gmail.com.

Reply via email to