ActionResult and async Method Using FastMapper, Error in TypeAdpter

0

I have the following problem with FastMapper. When implementing an ActionResult async when using the TypeAdapt it can not perform the asynchronous conversion, would anyone know how to do the conversion with FastMapper? Remember, when I do the conversion on hand and or without async the same works normally. Code that presents 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:

ErrorMessage:

Without using FastMapper it works normally, my problem is how to use FastMapper with Async? Do I have to implement anything in the part of the Model in order to 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);
    }
    
asked by anonymous 30.06.2016 / 16:59

1 answer

1

By the homepage documentation , Adapt is not asynchronous.

Switch to:

// GET: Credito/Details/5
public async Task<ActionResult> Details(int? id)
{
    if (id == null)
    {
        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    }
    var creditoTabela = await db.Creditos.FindAsync(id);

    CreditoViewModel creditoTela = TypeAdapter.Adapt<CreditoModel, CreditoViewModel> (creditoTabela);

    if (creditoTela == null)
    {
        return HttpNotFound();
    }
    return View(creditoTela);
}

You already use an asynchronous method within this Action . The FastMapper method does not have to be either.

    
30.06.2016 / 17:04