I'm using Dapper to make a select in the database and the return shows the name of the columns differently.
Does anyone know why this occurs?
Image below, left(JSON returns from API), right(SQL Server Table)
JSON result:
C# code:
Controller Method
IEnumerable<Romaneio> romaneios;
string query = "SELECT * FROM TB_ROMANEIOS";
romaneios = await connection.QueryAsync<Romaneio>(query)
The Class used by Dapper
public class Romaneio
{
public string ROMANEIO_ID { get; set; }
public string PRODUTO_ID { get; set; }
public string DESCRICAO { get; set; }
public string QTD_PALLET { get; set; }
public string QTD_CX { get; set; }
public string QTD_TOTAL { get; set; }
public string QTD_CX_PL { get; set; }
public string QTD_UN_CX { get; set; }
public int STATUS_ROMANEIO { get; set; }
public DateTime DATA_ROMANEIO { get; set; }
}
I had the same problem and I solved it by rewriting the attributes name, in your class you're using like this: ROMANEIO_ID
. Try rewrite to romaneio_id
.
Could you post the CLR object you're asking Dapper to map to?
Does using ADO.NET directly yield the same result?
For example:
using(var conn = new SqlConnection("your connection string")
{
await conn.OpenAsync();
using(var cmd = new SqlCommand("select * from TB_ROMANEIS", conn)
using(var rd = await cmd.ExecuteReaderAsync())
{
while(await rd.ReadAsync()){
var test = rd.GetValue(rd.GetOrdinal("STATUS_ROMANEIO"));
//what does test == here?
}
}
}
It's also worth asking, because I think we've all made this mistake at some point. But are you absolutely sure the database shown in the picture is the one you're querying?