Make a query using Entity Framework and Stored Procedures

Asked

Viewed 310 times

2

I have the procRetornaCliente process that receives the following parameters: Id, areaAtuacao, City. Mapping it on EDMX, I got a Complex Type (procRetornaClienteModel) with all fields mapped, but do not know how to make a query using the Entity Framework, I have already researched and every site makes a different example. My structure is as follows:

using (DataBaseAdmin db = new DataBaseAdmin())
{
    int id = Session["_id"];
    String areaAtuacao = Session["_areaAtuacao"].ToString();
    String Cidade = Session["_Cidade"].ToString();
}
  • 1

    This http://answall.com/a/23174/6026 has what you’re looking for.

1 answer

3


Have you ever tried something like this?

using (DataBaseAdmin db = new DataBaseAdmin())
{
    int id = Session["_id"];
    String areaAtuacao = Session["_areaAtuacao"].ToString();
    String Cidade = Session["_Cidade"].ToString();

    //retornar da procedure
    var object = db.procRetornaClienteModel(id);

    //manipular e salvar
    var cliente; // coloque aqui código pra transformar seu retorno em uma entidade cliente.
    cliente.AreaAtuacao = areaAtuacao;
    cliente.Cidade = Cidade;
    db.SaveChanges();
}

For a better answer it is necessary to have more information about what exactly your project does, what its entities are, etc. But I hope I have helped.

  • 1

    I modified it a little bit and apparently it’s working. Thank you!

  • For nothing! I’m happy to help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.