I have followed the example in https://bitbucket.org/twincoders/sqlite-net-extensions and mine appears a really strange error "System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.String'."
public class AgendamentoMotorista
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int IdAgendamento { get; set; }
public string DocumentoMotorista { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<AgendamentoAtivoConteinerDto> Conteineres { get; set; }
}
public class AgendamentoAtivoConteinerDto
{
[PrimaryKey, AutoIncrement]
public int Id2 { get; set; }
[ForeignKey(typeof(AgendamentoMotorista))]
public string Conteiner { get; set; }
public string PesoBruto { get; set; }
public string Imo { get; set; }
[ManyToOne]
public AgendamentoMotorista AgendamentoMotorista { get; set; }
}
Those are my classes that I'm using, I am establishing a relationship onetomany.
_conexao = new SQLiteConnection(config.Plataforma, System.IO.Path.Combine(config.DiretorioDb, "MotoristasAgendamento2.db3"));
_conexao.CreateTable<AgendamentoMotorista>();
_conexao.CreateTable<AgendamentoAtivoConteinerDto>();
}
public void InsertWithChildren(AgendamentoMotorista agendamento)
{
_conexao.InsertWithChildren(agendamento);
}
Anyone knows why this error is appearing? It happens when I use the UpdateWithChildren too.
EDIT
I have solved the problem, after the ForeignKey I must use a Int and not a string, the fix is here :
[PrimaryKey, AutoIncrement]
public int Id2 { get; set; }
[ForeignKey(typeof(AgendamentoMotorista))]
public int ConteinerId { get; set; }
public string Conteiner { get; set; }
public string PesoBruto { get; set; }
public string Imo { get; set; }
[ManyToOne]
public AgendamentoMotorista AgendamentoMotorista { get; set; }