Passing Parameters to Store Procedure

2

Follow the Search Function Code

public List<Pessoa> Buscar(string Nome)
{ 
    using(var db = new MyContext())
    {
        var Result = db.Database.SqlQuery<Pessoa>("EXEC SP_Busca_Cliente @Nome", Nome).ToList();
        return Result.ToList();
    }
}

    
asked by anonymous 02.10.2017 / 15:17

1 answer

4

There is, of course, the correct syntax (using your code as an example):

var result = context.Database.SqlQuery<Pessoa>(
    "SP_Busca_Cliente @Nome", new SqlParameter("@Nome", nome));

You do not need "Exec" before the procedure name, just put the procedure name and the parameter list.

Font .

    
02.10.2017 / 15:30