I'm having a problem using Dapper
.
I have a list of the Rubrica
class that contains the field valore
.
When I run a query with a JOIN and identify the agenda type, the valore
field remains set to null
My two classes Rubrica
and TipoAgenda
public class Rubrica // Same as table anagrafico_rubrica
{
public int id_rubrica { get; set; }
public string cod_anagrafica { get; set; }
public string descrizione_contatto { get; set; }
public TipoRubrica tipo { get; set; }
public string valore { get; set; }
}
public class TipoRubrica // Same as table anagrafico_tipo_rubrica
{
public int id_tipo_rubrica { get; set; }
public string descrizione_tipo_rubrica { get; set; }
}
I created a function that returns me a list of Agenda
doing a JOIN with table anagrafico_tipo_rubrica
public List<Rubrica> GetAgendaAnagrafico(string codiceAnagrafico)
{
using (DatabaseConnection db = new DatabaseConnection())
{
const string query = @"SELECT * FROM anagrafico_rubrica JOIN anagrafico_tipo_rubrica ON tipo = id_tipo_rubrica WHERE cod_anagrafica = @anagrafico";
var parametri = new { anagrafico = codiceAnagrafico };
return db.con.Query<Rubrica, TipoRubrica, Rubrica>(query, (rubrica, tipo) => { rubrica.tipo = tipo; return rubrica; }, parametri, splitOn: "tipo").ToList();
}
}
Here you can see what the query returns
And here you see how int the Agenda
list there is the value of valore
set to null