0
Viewmodel
public class ClienteResult
{
[Display(Name ="intParc_Cod")]
public int ClienteId { get; set; }
public string Nome { get; set; }
public string CPF { get; set; }
public decimal Saldo { get; set; }
}
Repositorio (Dapper)
public IEnumerable<ClienteResult> SaldoCliente(int id)
{
return
_context
.Connection
.Query<ClienteResult>(
"EXEC sp_cliente_saldo @Id", new {Id = id } );
}
Controller
[HttpGet("v1/cliente/saldocliente/{id:int}")]
public IActionResult SaldoCliente(int id)
{
return Ok(_repository.SaldoCliente(id));
}
Good afternoon,
I have a service (Web Api) that has a class (or Viewmodel) that returns the client and their balance. I get this data through an execution of a precedent and then call in a controller that results in JSON.
Well, the problem is that for me to return the JSON with its respective values to my Clienteresult class all its fields have to be the same as the one in the database table. I wanted to return with is in class (e.g., Clienteid, Name) and not as Procedure returns (codigo_cli, cli_name).
I’ve tried Data Annotation [Column("codigo_cli"]] and [Display(Name="Clienteid")], but it didn’t work.
Is there any other alternative?
It worked, it was cool. But I ended up using [Datacontract] and [Datamember]
– Torres