1

I take a good moment trying to insert information in a table that has a relation created many to many in windows phone 8.1. Since I can do in order that the information is inserted automatic in the intermediate table? I am using sqlite-net for the relations between tables, my entities they are

[Table("Compra")]
public class Compra
{
    [PrimaryKey, AutoIncrement]
    //[ForeignKey(typeof(Detalle))]
    public int Id_Compra { get; set; }
    public DateTime Fecha { get; set; }

    [ManyToMany(typeof(Detalle), CascadeOperations = CascadeOperation.All)]
    List<Producto> Productos { get; set; }
}

[Table("Producto")]
public class Producto
{
    [PrimaryKey, AutoIncrement]
    //[ForeignKey(typeof(Detalle))]
    public int Id_Producto { get; set; }
    public string Nombre { get; set; }
    public bool Comprado { get; set; }

    [ManyToMany(typeof(Detalle), CascadeOperations = CascadeOperation.All )]
    List<Compra> Compras { get; set; }
}

[Table("Detalle")]
public class Detalle
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [ForeignKey(typeof(Compra))]
    public int Id_Compra { get; set; }

    [ForeignKey(typeof(Producto))]
    public int Id_Producto { get; set; }

}

The function and the code to add product are the following ones

   private async void addProducto()
    {
        Producto prod = new Producto();   

        prod.Nombre = tbNuevoProducto.Text;
        prod.Comprado = false;

        SQLiteAsyncConnection conn = new SQLiteAsyncConnection("CarroCompra.db");
        conn.InsertAsync(prod);

    }

Is the well-read one that with InsertWhithChildren I could to insert in the intermediate table automatic but I it cannot use in the application. Much would be grateful that someone was helping myself because I go 2 days trying and I have not seen anything for Internet

What kind of using sqlite I should use and which conector sqlite and path shall I use ?

I need that on having inserted a product it is inserted automatic in the table detail

Fernando
  • 21
  • 4

0 Answers0