I am facing a problem using Dapper. I have two models:
public class ClientEventsModel
{
public int Id { get; set; }
public int ClientId { get; set; }
public ClientEventTypeLog EventType {get; set;}
public int Value { get; set; }
public DateTime Date { get; set; }
public string? Doer { get; set; }
}
[Serializable]
public class ExtentedClientEventsModel : ClientEventsModel
{
public List<string> Values { get; set; } = new List<string>();
}
One is inherited from the other. And a request in the form:
var sqlStr = $@"SELECT ce.Id, ce.ClientId, ce.EventType, ce.Value, ce.Date, a.UserName AS Doer, cevn.`Values` FROM clients.client_events ce
LEFT JOIN `z-price`.aspnetusers a ON ce.Doer = a.Id_num
LEFT JOIN clients.clients_events_value_name cevn ON ce.Id = cevn.ClientEventsId
where ClientId = {clientId} and Date BETWEEN '{from.ToMysql()}' and '{to.AddDays(1).ToMysql()}'";
var result = DefaultConnection.Query<ExtentedClientEventsModel>(sqlStr);
When I execute the query in the client it returns 16 records. But when I use Dapper it returns 4 records. And only those with the Doer == null field. I tried replacing the model with a dynamic type, but it didn't help.