-2
That is the mistake:
System.Data.Entity.Core.EntityCommandExecutionException: 'The data reader is incompatible with the specified 'TreinamentoCrudApi.Context.Cidade'. A member of the type, 'id', does not have a corresponding column in the data reader with the same name.'
If in SP I put one:
select * from tabela
--> works
but if I do it:
select nome from tabela
--> returns the cited error
My model is like this:
public class Cidade
{
[Key]
public int id { get; set; }
[Required]
public String nome { get; set; }
}
SP call in API
public class GetCidade
{
BancoContext banco = new BancoContext();
public List<Cidade> GetCidades()
{
return banco.Database.SqlQuery<Cidade>("exec sp_cons_cidade").ToList();
}
}
My proc in the bank runs normally. How do I resolve this?
The error is saying that the query does not return the column
id
that is expected, try to include it in the query.– Caique Romero
In doing
SqlQuery<Cidade>
is waiting for SP to return all the fields that make up that class, where, in this case, the columnid
is included.– João Martins
If your model has two fields, you cannot return only one
– Ricardo Pontual