1

Windows Phone 8.1 で作成された多対多のリレーションを持つテーブルに情報を挿入しようとしました。情報が中間テーブルに自動的に挿入されるようにすることはできますか?テーブル間の関係にsqlite-netを使用しています。私のエンティティは

[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; }

}

プロダクトを追加する関数とコードは次のとおりです。

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

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

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

    }

InsertWhithChildren を使用すると、中間テーブルに自動的に挿入できますが、アプリケーションでは使用できないというよく読まれたものです。私は2日間試してみましたが、インターネットで何も見られなかったので、誰かが自分自身を助けてくれたことにとても感謝しています

どのような sqlite を使用する必要があり、どのコネクタ sqlite とパスを使用する必要がありますか?

製品を挿入すると、テーブルの詳細に自動的に挿入される必要があります

4

0 に答える 0