1
I have the following code that gives me an error:
The inline Constraint resolver of type 'Defaultinlineconstrainaintresolver' was Unable to resolve the following inline Constraint: 'String'.
Exception Details: System.Invalidoperationexception: The inline Constraint resolver of type 'Defaultinlineconstraintresolver' was Unable to resolve the following inline Constraint: 'String'.
//http://localhost:1608/api/ApiCidade/consulta/clienteLoginSenha/
[HttpGet]
[Route("consulta/clienteLoginSenha/{email:long};{senha:long}")]
public HttpResponseMessage ClientePorLoginSenha(string email, string senha)
{
try
{
var tCliente = new ClienteAplicacao();
var listarDeClientes = tCliente.ListarPorLoginSenha(email,senha);
return Request.CreateResponse(HttpStatusCode.OK, listarDeClientes.ToArray());
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
//http://localhost:1608/api/ApiCidade/consulta/clientePorNome/e
[HttpGet]
[Route("consulta/clientePorNome/{nome:String}")]
public HttpResponseMessage ClientePorNome(string nome)
{
try
{
var tCliente = new ClienteAplicacao();
var listarDeClientes = tCliente.ListarPorNome(nome);
return Request.CreateResponse(HttpStatusCode.OK, listarDeClientes.ToArray());
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
consultation in the application :
public List<Cliente> ListarPorNome(string nome)
{
var strQuery = string.Format("select * from clientes where nome like {0}", nome + '%');
using (contexto = new Contexto())
{
var retornoDataReader = contexto.ExecutaComandoComRetorno(strQuery);
return TransformaReaderEmListaObjetos(retornoDataReader);
}
}
private List<Cliente> TransformaReaderEmListaObjetos(SqlDataReader reader)
{
var clientes = new List<Cliente>();
while (reader.Read())
{
Cliente cliente = new Cliente()
{
Id = reader["id"] == DBNull.Value ? 0 : Convert.ToInt32(reader["id"]),
Nome = reader["nome"] == DBNull.Value ? string.Empty : reader["nome"].ToString(),
DataNascimento = reader["data_nascimento"] == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(reader["data_nascimento"]),
Email = reader["email"] == DBNull.Value ? string.Empty : reader["email"].ToString()
};
clientes.Add(cliente);
}
reader.Close();
return clientes;
}
What kind of method Listarpornome (tCliente.Listarpornome(name);) returns? When I use, I return directly to the list (List<T>).
– Pedro Camara Junior
I added the most complete code, see if you can help me
– Harry
I don’t think you need to convert to array (listDeClientes.Toarray()) because it is already a list. Already tried to return only the list?
– Pedro Camara Junior
my question is on this line:[Route("query/clientPorNome/{name:String}")] I cannot use this way.
– Harry