3
No. NET Core I know we have the async
and await
for request async.
So far so good, but many frameworks in the market are creating methods with the signature MetodoAsync()
and has the method without being async Metodo()
.
We can use async
thus
[HttpGet]
public async Task<JsonResult> Get()
{
return await Task.Run(() => Json(_fachadaGrupo.BuscarTodos()));
}
Remembering that in internal methods _fachadaGrupo.BuscarTodos()
. there is no method async it uses a connection to nhibernate database and it does not have the method Async()
at the moment. Soon then wanted to know if this still has the same efficiency and the same logic happens internally in which the thread and released for new requests. Or is it the same as not having.
// facade
public IEnumerable<GrupoDto> BuscarTodos()
{
return _buscarTodos.Buscar();
}
// Serviço
public IEnumerable<GrupoDto> Buscar()
{
IRepositorioGrupo repositorioGrupo = new RepositorioGrupo(_nHibernateHelper);
return repositorioGrupo.Lista(_usuario);
}
// repositorio
public IEnumerable<GrupoDto> Lista(Usuario usuario)
{
Usuario usuarioAlias = null;
Grupo grupo = null;
GrupoDto grupoDto = null;
return Sessao.QueryOver(() => grupo).JoinAlias(() => grupo.Usuario, () => usuarioAlias)
.SelectList(list => list.Select(() => grupo.Id).WithAlias(() => grupoDto.Id)
.Select(() => grupo.Descricao).WithAlias(() => grupoDto.Descricao))
.TransformUsing(Transformers.AliasToBean<GrupoDto>())
.Where(g => g.Usuario == usuario).OrderBy(g => g.Id).Desc.List<GrupoDto>();
}
if you want to continue using ASP.NET Core, I advise you to leave Nhibernate, it has a dependency with the
Iesi.Collections
which has not been updated for some years, theISession
are notthread safe
, which makes it impossible to implement theasync/wait
with the same, and finally, the same was not done in the.net standard
, you can even use the same incompatibilidade
with the4.6.1
, but you will have no guarantees... so I advise you to use theEF Core 2.0
, which is much more efficient and has a much more mature API.– Tobias Mesquita
A compatibility with . net standard , and in the version about to be released we will already have support for async/Wait (version 5.0 of it) https://github.com/nhibernate/nhibernate-core/pull/693 (version 5.0) and in version 5.1 we probably already have support with . net standard https://github.com/nhibernate/nhibernate-core/pull/633
– Roberto
I’m sorry, but this NH 5.0 has been in development for quite some time now, and has always been delayed. Unless your project only goes into production in 2022, it is not a good idea to wait for a stable version of it.
– Tobias Mesquita