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?
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With