Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping My Head Around await async and NHibernate

Given this code:

private ISession _session;

public async Task<T> GetAsync<T>(int id) where T : ISomeEntity
{
    //how to call and return _session.Get<T>(id) asynchronous
}

Is it possible to call NHibernate ISession.Get<T>() asynchronously? Advisable? Not worth it?

like image 505
mxmissile Avatar asked May 08 '15 17:05

mxmissile


1 Answers

NHibernate does not support Async await in the sense of entity framework does by default. However it would be recommended to do so (if you could) since a database call is an IO call which is a very good candidate to make it async. As a result while waiting response from DB your thread will return to the pool instead of being pend and it will make your app more scalable. Now coming to async support. I have forked NHibernate to achive this. In my fork which I call NHibernateX, there are Async Methods like GetAsync, ListAsync, ToListAsync etc Here's the source and nuget package:

https://github.com/ReverseBlade/nhibernate-core

https://www.nuget.org/packages/NHibernateX/

like image 151
Onur Gumus Avatar answered Oct 06 '22 05:10

Onur Gumus