0
I have the following problem with Fastmapper. When implementing an Actionresult async when using Typeadapt it cannot perform the asynchronous conversion, would anyone know how to do the conversion with Fastmapper? Remembering, when I do the conversion by hand and or without async the same works normally. Code presenting the problem:
// GET: Credito/Details/5
public async Task<ActionResult> Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var creditoTabela = db.Creditos.FindAsync(id);
CreditoViewModel creditoTela = await TypeAdapter.Adapt<CreditoModel, CreditoViewModel> (creditoTabela);
if (creditoTela == null)
{
return HttpNotFound();
}
return View(creditoTela);
}
Validation and error image:
Error message:
Without using Fastmapper works normally, my problem is how to use Fastmapper with Async? I have to implement something in the Model part to make it work?
// GET: Credito/Details/5
public async Task<ActionResult> Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var creditoTabela = db.Creditos.Find(id);
CreditoViewModel creditoTela = new CreditoViewModel() {
Codigo = creditoTabela.Codigo,
Descricao = creditoTabela.Descricao,
Nome = creditoTabela.Nome,
Imagem = creditoTabela.Imagem
};
if (creditoTela == null)
{
return HttpNotFound();
}
return View(creditoTela);
}
Had thought the same at first but persists and still presents a warning informing that the method will be synchronous even the so-called async.
– Napoleão Menezes
That’s right. I forgot
await
invar creditoTabela = await db.Creditos.FindAsync(id);
. Look now.– Leonel Sanches da Silva
Boy was obvious and I didn’t notice, the consultation the base was asyn and had not set the await in it, thanks and thanks.
– Napoleão Menezes